I want to force a Number to be a Float, after JSON.stringify(). Unfortunately JSON.stringify() deletes the 1 .0.
Example :
JSON.stringify(1.0) // "1"
Wanted outcome:
JSON.stringify(1.0) // "1.0"
I'm using an API which wants an object in JSON-Format, but it only understands decimal values. So I wanted to ask if it is possible using JSON.stringify to generate the string with decimal values without using Regex-.replace-magic
JSON.stringify(1)though? There's no such thing as a "float" in JavaScript, onlyNumber.stringifyhas an overload which takes a function. Use that to determine what to output.JSON.stringify({Test:1}, function(key, value){ if(key == 'Test') { return value.toFixed(1) } return value; }); // "{"Test":"1.0"}". I dont want to have the quotation marks after "Test":**"** 1.0 "*