When performing this action...
var data = JSON.parse('{"myNum":0.0}') ;
If you access data.myNum
, the output will be 0
. (Understandable.)
However, if you execute data.myNum.toString()
, the result will be "0"
.
The main goal is to convert it into the string "0.0"
.
In reality, I don't have control over the JSON input as it comes from a web service... The intention is to parse the JSON using the browser's JSON parser and differentiate between numeric values of 0
and 0.0
.
Is there a way to achieve this without manually examining the JSON string? Given the necessity to utilize the browser's native JSON parser for efficiency. (This pertains to a Chrome extension only, compatibility with other browsers is not essential.)