Javascript - Math ceil() Method

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

Description

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

If the passed argument is an integer, the value will not be rounded.

Syntax

Math.ceil(x)

Parameter Values

Parameter Require Description
x Required. The number you want to round

Return

A Number, representing the nearest integer when rounding upwards

Example

Round a number upward to its nearest integer:

Demo

//round the number 1.4 upward to its nearest integer.
console.log(Math.ceil(1.4));

Result

Use the ceil() method on different numbers:

The result of a,b,c,d,e, and f will be:

Demo

//round different numbers upwards to the nearest integer.
var a = Math.ceil(0.20);
var b = Math.ceil(0.50);
var c = Math.ceil(3);
var d = Math.ceil(2.1);
var e = Math.ceil(-5.1);
var f = Math.ceil(-4.9);

var x = a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f;
console.log(x);/*from  ww w .j  a va2 s  .  c  o m*/

Result