Ceiling and floor
suggest changeceil()
Math.ceil() rounds a number toward +∞ to an integer and returns that value.
Syntax:
Math.ceil(n);
Example:
console.log(Math.ceil(0.60)); // 1
console.log(Math.ceil(0.40)); // 1
console.log(Math.ceil(5.1)); // 6
console.log(Math.ceil(-5.1)); // -5
console.log(Math.ceil(-5.9)); // -5
floor()
Math.floor() rounds a number toward −∞ to an integer and returns that value.
Syntax:
Math.floor(n);
Example:
console.log(Math.floor(0.60)); // 0
console.log(Math.floor(0.40)); // 0
console.log(Math.floor(5.1)); // 5
console.log(Math.floor(-5.1)); // -6
console.log(Math.floor(-5.9)); // -6
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents