How to prevent removing decimal point when parsing JSON?

后端 未结 4 1404
灰色年华
灰色年华 2020-12-11 16:36

If you do this...

var parsed = JSON.parse(\'{\"myNum\":0.0}\') ;

Then when you look at parsed.myNum, you just get 0

4条回答
  •  一整个雨季
    2020-12-11 17:13

    It shouldn't matter, 00000.00000 is 0 if you try JSON.parse('{"myNum":0.00001}') you'll see a value of { myNum=0.0001 } If you really need it to hold the decimal you'll need to keep it a string JSON.parse('{"myNum":"0.0"}')

提交回复
热议问题