I have to send JSON data from a NodeJS app to a Scala server. The Scala server expects a value to be a double but I am having an issue when the value I have to send is sharp and thus have .00
as decimals. When sent, it becomes an integer which obviously generates an error on the server side, which expects a double.
The question is, is there a way to force a float in NodeJS to stay a float with .00
(or .0
) as dicimals without becoming a string (which happens with .toFixed(2)
for instance) ?
Basically, I want this to do what I want:
var division = (2.0/1.0); // is a sharp float thus becomes an integer (javascript "number" with no decimals) => 2
var stringNumber = parseFloat(division).toFixed(2); // is unfortunately a string => "2.00"
var floatNumber = magic(stringNumber); // would be a float => 2.00
var test = (typeof(floatNumber) === 'number'); // would be true!
Thank you for your help