Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 544 Bytes

number-methods.md

File metadata and controls

21 lines (15 loc) · 544 Bytes

Number methods.

Just below are some of the useful methods you can use with numbers.

// returns number of digits after the decimal point
console.log(num.toFixed(2));

// Math.round() - rounds up a number
console.log(Math.round(num));

// Math.floor() - rounds down a number
console.log(Math.floor(num));

// Math.ceil() - rounds up a number to the largest interger
console.log(Math.ceil(num));

// Math.random() - generates a random number
let randomNum = Math.floor(Math.random() * (20 - 10 + 1));
console.log(randomNum);