JS: Number.prototype.toFixed
number.toFixed(n)-
- Return a string representation of number, with n digits after decimal, padded by 0 if necessary.
- The number may be rounded up.
console.assert(3.12345.toFixed(0) === "3"); console.assert(3.12345.toFixed(1) === "3.1"); console.assert((3.1).toFixed(3) === "3.100"); // the arg to toFixed cannot be negative. Else, RangeError // toFixed may round up console.assert((3.56).toFixed(0) === "4"); console.assert((3.56).toFixed(1) === "3.6");