Home > Web Front-end > Front-end Q&A > What does ceil mean in JavaScript

What does ceil mean in JavaScript

WBOY
Release: 2022-04-11 15:26:34
Original
2478 people have browsed it

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)".

What does ceil mean in JavaScript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What does ceil mean in JavaScript

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)
Copy after login

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>
Copy after login

Output result:

What does ceil mean in JavaScript

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template