Skip to main content Accessibility Feedback

Numbers

Number.prototype.toFixed()

Format a number to a fixed number of decimal places. Pass in the number of decimal places as an argument.

let pi = 3.14159;
let eleven = 11;

// returns 3.14
pi.toFixed(2);

// returns 11.000
eleven.toFixed(3);

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.