How to keep value as number in JSON.stringify()
toFixed
returns a string. If you want to output a number, just use parseFloat
:
JSON.stringify({
"payer": "a cat",
"price": parseFloat(amount)
});
I don't think there's a way to output a number to any precision after the decimal without converting it to a string.
I think Number() will work too
The differences are here. I have worked with both in JSON.stringify
var data = JSON.stringify({
"payer": "a cat",
"price": Number(amount)
});