What does math.floor do?
xxxxxxxxxx
It rounds the number down. For eg. Math.floor(2.9) is 2
xxxxxxxxxx
console.log(Math.floor(5.95));
// expected output: 5
console.log(Math.floor(5.05));
// expected output: 5
console.log(Math.floor(5));
// expected output: 5
console.log(Math.floor(-5.05));
// expected output: -6
xxxxxxxxxx
console.log(Math.floor(5.95));
// expected output: 5
console.log(Math.floor(5.05));
// expected output: 5
xxxxxxxxxx
Math.floor(4.9);
Math.floor(4.7);
Math.floor(4.4);
Math.floor(4.2);
Math.floor(-4.2);
xxxxxxxxxx
// The floor() method rounds the specified double value downward to the nearest integer and returns it.
// The rounded value will be equal to the mathematical integer.
// That is, the value 3.24 will be rounded to 3.0 which is equal to integer 3.
// We can only use float numbers in floor().
// EXAMPLE: 1
let floating_num = Math.floor(2.65);
console.log(floating_num);
// OUTPUT: 2
// EXAMPLE: 2
let floating_num_2 = Math.floor(-2.65);
console.log(floating_num_2);
// OUTPUT: -3
// EXAMPLE: 3
let floating_num_3 = Math.floor(5);
console.log(floating_num_3);
// OUTPUT: 5
xxxxxxxxxx
// Math.floor returns the floor of a number
console.log(Math.floor(1.5)); // -> 1
// Using two bitwise not operators '~' you can also get the floor of a number
console.log(~~1.5); // -> 1
xxxxxxxxxx
console.log(Math.floor(5.95)); // output: 5
console.log(Math.floor(-11.23)); // output: -12
console.log(Math.floor(9.78)); // output: 9