Round and Round
- PI – returns 3.14….
- round() – round floating point to nearest integer
- floor() – round floating point down
- ceil() – round floating point up
- random() – generate random number between 0 and 1
There is also, min(), max() and abs(), which returns an absolute number.
var num = 1.234;
console.log(Math.round(num));// returns 1
console.log(Math.floor(num));// returns 1
console.log(Math.ceil(num));// returns 2
console.log(Math.random());// returns value between 0 & 1
Note: If you want a random number between numbers other than 0 & 1, you can do that easily enough…
Math.floor((Math.random() * 0) + 1);// Returns random number between 0 and 50