📅  最后修改于: 2023-12-03 15:17:33.443000             🧑  作者: Mango
In JavaScript, Math.floor()
method is used to round down a given number to the nearest integer value.
Math.floor(x)
The x
parameter represents the number that needs to be rounded down to the nearest integer value.
The Math.floor()
method always returns an integer value. If the passed argument is already an integer, then the method returns the same value.
let num1 = 10.9;
let num2 = 3;
let roundedNum1 = Math.floor(num1); // 10
let roundedNum2 = Math.floor(num2); // 3
console.log(roundedNum1);
console.log(roundedNum2);
In the above example, we have used the Math.floor()
method to round down the values of num1
and num2
variables to their nearest integer values.
The Math.floor()
method is a handy method of rounding down any number to its nearest integer value. It is important to remember that this method always returns an integer value.