How can I change an integer like 10 to 10.00 in JavaScript without changing the type to string.
I know that this can be achieved by toFixed(2)
but that returns a string to which I have to do parseFloat
again which removed the decimal points.
var er = 10
console.log(parseFloat(er.toFixed(2))) // returns 10 expected: 10.00
You could convert it to Number
(with unary +
) and apply toFixed
, to get a string again.
var u = "10"; // string
f = (+u).toFixed(2); // string
console.log(f);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments