treat json objects value as integer :
javascript JSON 값을 정수로 변경
[Q]
I have a json file which I am accessing through JS
latitude =data8.weblandmarks8[j].latitude + latitude;
should add all the latitudes so that I could average them later instead it just concatenates them How should i achieve what I want to
Json entry
"latitude": "28.14331",
[A]
Aside from using parseFloat you could convert to Number, it's slightly faster and usable for both integers and floats1:
latitude = Number(data8.weblandmarks8[j].latitude) + latitude;
1 another advantage for integers is that you don't need to supply a radix. Number('09') returns 9, whereas parseInt('09') (i.e. parseInt without a radix) returns 0 (that's because parseIntdefaults to an octal - radix 8).
[출처] https://stackoverflow.com/questions/6174105/treat-json-objects-value-as-integer