📅  最后修改于: 2023-12-03 15:16:05.184000             🧑  作者: Mango
In JavaScript, the Math.floor()
method is used to round down a decimal number to its nearest integer. It returns the largest integer less than or equal to the given number.
Math.floor(x)
x
: Required. The number to round down.let num1 = 5.5;
let num2 = 9.9;
let num3 = -4.6;
console.log(Math.floor(num1)); // Output: 5
console.log(Math.floor(num2)); // Output: 9
console.log(Math.floor(num3)); // Output: -5
In the above example, we have declared three variables with decimal numbers. We have used Math.floor()
method to round down these numbers to their nearest integer.
Math.floor()
is a useful method in JavaScript for rounding down decimal numbers to their nearest integers. It works by returning the largest integer less than or equal to the given number.