Number Methods

Methods for working with numbers.

Examples

toFixed()

Rounding to specific decimal places.

let x = 9.656;
console.log(x.toFixed(0)); // 10
console.log(x.toFixed(2)); // 9.66

toPrecision()

Formatting to a total number of digits.

let x = 9.656;
console.log(x.toPrecision(2)); // 9.7
console.log(x.toPrecision(4)); // 9.656

toString()

Converting numbers to strings.

let x = 123;
console.log(x.toString()); 
console.log((100 + 23).toString());

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.