Home > Web Front-end > JS Tutorial > body text

javascript ceil() 获取小数的整数(取整)

WBOY
Release: 2016-06-01 09:54:40
Original
1633 people have browsed it

ceil() 返回大于等于其数字参数的最小整数。

基本语法:

<code class="language-javascript">Math.ceil(number)</code>
Copy after login

必选项number 参数是数值表达式。如何传入一个非数值,则返回NaN。

返回值

大于等于 x,并且与它最接近的整数。

说明

ceil() 方法执行的是向上取整计算,它返回的是大于或等于函数参数,并且与之最接近的整数。

实例:

<code class="language-javascript"><script type="text/javascript">
document.write(Math.ceil(0.60) + "<br />")
document.write(Math.ceil(0.40) + "<br />")
document.write(Math.ceil(5) + "<br />")
document.write(Math.ceil(5.1) + "<br />")
document.write(Math.ceil(-5.1) + "<br />")
document.write(Math.ceil("ma"))
</script></code>
Copy after login

在线运行

运行结果:

<code class="language-javascript">1
1
5
6
-5
NaN</code>
Copy after login

 

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