How to use ceil in JavaScript

In this article, I will explain use of ceil() method in JavaScript.
  • 1872

JavaScript ceil() Method

  • ceil() method of math object is used to get rounds a number UPWARDS to the nearest integer.

  • ceil() method returns the smallest integer greater than or equal to a number.

  • In ceil() method, if the argument value is an integer, the value will not be rounded.

Syntax

Math.ceil(x)

  • x is a Required number, you want to round

Example

In the following example show to ceil() method returns smallest integer of numbers.

<html>

<head>

<title>JavaScript Math ceil() Method</title>

</head>

<body>

<h3 style="color:Blue">JavaScript ceil() Method Example</h3>

<script type="text/javascript">

    var a = Math.ceil(65.90);

    document.write("First Value of ceil : " + a);

    var b = Math.ceil(25.95);

    document.write("<br />Second Value of ceil : " + b);

    var c = Math.ceil(-65.90);

    document.write("<br />Third Value of ceil: " + c);

    var d = Math.ceil(-25.95);

    document.write("<br />Fourth Value of ceil: " + d);

</script>

</body>

</html>

Output

ceil method.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.