Home >Web Front-end >JS Tutorial >javascript ceil() 获取小数的整数(取整)

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 09:54:401669browse

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

基本语法:

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

必选项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>

在线运行

运行结果:

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

 

Statement:
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