内容目录
Math.ceil()函数用于返回大于或等于指定数字的最小整数,一般称为向上取整。
该函数属于JavaScript的内置全局对象Math,所有主流浏览器均支持该函数。
语法
静态函数Math.ceil()的语法如下:
Math.ceil( number )
参数
| 参数 | 描述 |
|---|---|
| number | Number类型指定的数值 |
返回值
Math.ceil()的返回值为Number类型。返回大于或等于参数number的最小整数。
如果参数不是数字,或无法转换为数字,则返回NaN。
示例&说明
document.writeln( Math.ceil( 3.14 ) ); // 4
document.writeln( Math.ceil( -0.18 ) ); // 0
// 如果是整数,则返回其本身
document.writeln( Math.ceil( 5 ) ); // 5
// 如果无法转换为数字,则返回NaN
document.writeln( Math.ceil( "CodePlayer" ) ); // NaN

0 条评论
撰写评论