views:

50

answers:

2
(27.19, 78.01)

i have this information in javascript and need in this form.

27.19N , 78.00E

if 27.19 is positive then include N after them otherwise S then it can be 27.19S

if 78.01 is positive then include E after them otherwise W then it can be 78.01W

how i can do this in javascript.

+3  A: 
var data = [27.19, -78.01];
var formatted = data[0] + ((data[0] > 0) ? 'N' : 'S') + ' , ' + 
                data[1] + ((data[1] > 0) ? 'E' : 'W');
alert(formatted);
Darin Dimitrov
Looks right, except that it looks like the question was about starting with a string '"(27.19, 78.01)"', so some parsing of the string would be required first?
jball
+3  A: 
function convert(tuple) {
   var pairs = tuple.substring(1, tuple.length-1).split(/,\s?/);
   pairs[0] = parseFloat(pairs[0]);
   pairs[1] = parseFloat(pairs[1]);
   return [Math.abs(pairs[0]) + (pairs[0] >= 0 ? "N" : "S"),
           Math.abs(pairs[1]) + (pairs[1] >= 0 ? "E" : "W")].join(" , ");
}
CD Sanchez
@Daniel thank's a lot.
4thpage