-1
(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.

0

2 Answers 2

2
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(" , "); } 
Sign up to request clarification or add additional context in comments.

Comments

2
var data = [27.19, -78.01]; var formatted = data[0] + ((data[0] > 0) ? 'N' : 'S') + ' , ' + data[1] + ((data[1] > 0) ? 'E' : 'W'); alert(formatted); 

1 Comment

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?