I have an int, say, var myInt = 24
and I need it to display it as a float like this: 24,000
. Is it even possible in javascript?
Important: converted float should be a number, not a string
I have an int, say, var myInt = 24
and I need it to display it as a float like this: 24,000
. Is it even possible in javascript?
Important: converted float should be a number, not a string
You can use toFixed()
to add zeros after the decimal point.
var myInt = 24;
console.log(myInt.toFixed(3));
Use Number.toFixed:
var int = 24
document.write('<pre>' + JSON.stringify(int.toFixed(3), 0, 4) + '</pre>');