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",

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

[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

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수

등록된 글이 없습니다.

대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED