Search code examples
javascriptjsonstringify

unable to use parseFloat after JSON Stringify


I have a line of code which says --

var latitude = JSON.stringify(place.lat);

when I do alert(latitude) -- It gives me output "33.232342" .But I want the number so when I do

var latitude = parseFloat(JSON.stringify(place.lat));

I get NaN. Could someone tell me what the problem might be?

Thanks


Solution

  • Your place.lat is already a string. So doing JSON.stringify() makes ""33.232342"".
    Just:

    parseFloat(place.lat);