What is best way to parse JSON number as String in javascript
Example:
{
"a": 10.00
}
Notice I do not have control over value 10.00. I cannot add there "+''". I want to keep the decimal places, but it is not rule that there have to be 2 decimals.
Result should be 10.00 not 10
JSON.parsewill do just fine. The actual number representation for10and10.00are exactly the same. If you want to display/format the number in a certain way then you can use.toFixed:(10)..toFixed(2). If you want to display the number exactly how it is written in the JSON document then you are out of luck. The value would have to be provided as a string.<p class="amount">${{ parsed.a.toFixed(2) }}</p>or whatever your render engine's equivalent is."10.00"not10.00,"1.928346", not1.928346, etc) but if you can't do that, then you are out of luck: write code that checks whether there is a fractional value, if there is, use the number directly, and if there isn't, use toFixed(...) if you always want to see a minimum number of decimal places.