Home > Article > Web Front-end > What does ceil mean in JavaScript
In JavaScript, ceil means "round up". This method can round a number. The returned result is an integer greater than or equal to the specified value and closest to the specified value. If the method If the parameter is an integer, the value remains unchanged, and the syntax is "Math.ceil (specified value)".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The ceil() method can round up a number.
If the parameter is an integer, the value remains unchanged.
Note: The ceil() method performs rounding calculation, and it returns the integer that is greater than or equal to the function parameter and is the closest to it.
The syntax is:
Math.ceil(x)
x Required. Must be a numeric value.
Return value
Number is greater than or equal to x, and is the closest integer to it.
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p id="demo">单击按钮,不同数值上升到最近的整数。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var a=Math.ceil(0.60); var b=Math.ceil(0.40); var c=Math.ceil(5); var d=Math.ceil(5.1); var e=Math.ceil(-5.1); var f=Math.ceil(-5.9); var x=document.getElementById("demo"); x.innerHTML=a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f; } </script> </body> </html>
Output result:
[Related recommendations: javascript video tutorial, webfrontend】
The above is the detailed content of What does ceil mean in JavaScript. For more information, please follow other related articles on the PHP Chinese website!