Math ceil() Method - Javascript Math

Javascript examples for Math:ceil

Description

The ceil() method rounds a number up to the nearest integer.

Parameter Values

Parameter Description
x Required. The number you want to round

Return Value:

A Number, representing the nearest integer when rounding upwards

The following code shows how to Round a number upward to its nearest integer:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  w  w  w .  jav  a 2 s . c o m*/
    var a = Math.ceil(0.60);
    var b = Math.ceil(1.40);
    var c = Math.ceil(5);
    var d = Math.ceil(15.1);
    var e = Math.ceil(-5.1);
    var f = Math.ceil(-15.9);

    var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials