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

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
263 서버 사이드 렌더링 그리고 클라이언트 사이드 렌더링 file 졸리운_곰 2018.11.02 801
262 AWS Certified Solutions Architect - Associate 2018 후기 file 졸리운_곰 2018.10.31 661
261 AWS 자격증 준비하기 file 졸리운_곰 2018.10.31 996
260 AWS 자격증 (아키텍트) 준비요령 file 졸리운_곰 2018.10.31 778
259 AWS Certified Solutions Architect – Associate Exam 시험 후기 file 졸리운_곰 2018.10.31 820
258 underscore.js로 편해지자 졸리운_곰 2018.10.16 545
257 Express 앱용 프로세스 관리자 졸리운_곰 2018.10.16 604
256 [vue.js] eclipse에서 vue.js 시작하기 file 졸리운_곰 2018.09.18 1064
255 카드형 디자인/갤러리/리스트 코딩하기. file 졸리운_곰 2018.09.06 481
254 jquery json에서 null 값 삭제 졸리운_곰 2018.09.05 307
253 jquery .append(Html). 에서 claas 적용 졸리운_곰 2018.09.05 241
252 JavaScript / Method / .split() – 문자열 분할하는 속성 file 졸리운_곰 2018.09.05 403
251 Javascript - 문자열에서 큰 따옴표를 제거하고 싶습니다. 졸리운_곰 2018.09.05 468
250 [JavaScript] Object.keys, json Object 반복문 돌리기 for...in 문 졸리운_곰 2018.09.05 595
249 javascript JSON Object의 key 개수(length) 구하기. 졸리운_곰 2018.09.05 490
248 jQuery Mobile Form Example file 졸리운_곰 2018.09.04 428
» treat json objects value as integer : javascript JSON 값을 정수로 변경 졸리운_곰 2018.09.03 279
246 Check if a key exists inside a json object : JSON 키값이 있는지 조사 졸리운_곰 2018.09.03 465
245 Grouping JSON by values : JSON 값으로 그룹핑 분류 졸리운_곰 2018.09.01 485
244 간단한 워드프레스 숏코드 만드는 방법 총정리 졸리운_곰 2018.09.01 718
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED