2

Have String {"a":100.000} and I need to parse it as JSON object. When I run JSON.parse("{\"a\":100.000}"), output is {a: 100}.

How do I retain the original format of value after parsing it as JSON object?

Santosh Hegde
  • 3,420
  • 10
  • 35
  • 51
  • 7
    It's not possible to have a *number* that retains excess fractional zeroes. Numbers in JavaScript don't have a display formatting associated with them since `100 === 100.0` and `100 === 100.00` and `100 === 100.000` etc they are all *the same number*. JavaScript will display all these as `100` as there is no reason it would add the fractional part. If you want a formatted number, you need to convert it to a string. – VLAZ Jul 09 '20 at 09:36
  • there is no way to keep decimals after JSON.parse. Check this answer https://stackoverflow.com/questions/5520399/how-to-prevent-removing-decimal-point-when-parsing-json – JSEvgeny Jul 09 '20 at 09:43

0 Answers0