JavaScript Arithmetic (Math) Ceiling and Floor

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

ceil()

The ceil() method rounds a number upwards to the nearest integer, and returns the result.

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()

The floor() method rounds a number downwards to the nearest integer, and returns the result.

Syntax:

Math.floor(n);

Example:

console.log(Math.ceil(0.60)); //  0
console.log(Math.ceil(0.40)); //  0
console.log(Math.ceil(5.1));  //  5
console.log(Math.ceil(-5.1)); // -6
console.log(Math.ceil(-5.9)); // -6


Got any JavaScript Question?