Javascript Math 中常用函数<一>--ceil(),floor(),round()
2013-05-09 17:38
776 查看
一、ceil( ) , floor( ),round( )
ceil():把小数向上舍入成整数,如果是负数相当于vbscript
中的Fix()函数
例:
alert(Math.ceil(10.1))//返回11
alert(Math.ceil(10.5))//返回11
alert(Math.ceil(10.9))//
返回11
alert(Math.ceil(-10.1))//返回-10
alert(Math.ceil(-10.5))//返回-10
alert(Math.ceil(-10.9))//
返回-10
floor():把小数向下舍入成整数 ,相当于vbscript中Int(
)
例:
alert(Math.floor(10.1))//返回10
alert(Math.floor(10.5))//返回10
alert(Math.floor(10.9))//
返回10
alert(Math.floor(-10.1))//返回-11
alert(Math.floor(-10.5))//返回-11
alert(Math.floor(-10.9))//
返回-11
round():进行四舍五入 ,相当于vbscript中round( )注意负数
例:
alert(Math.round(10.1))//返回10
alert(Math.round(10.5))//返回11
alert(Math.round(10.9))// 返回11
alert(Math.round(-10.1))//返回-10
alert(Math.round(-10.50))//返回-10
alert(Math.round(-10.51))//返回-11
alert(Math.round(-10.9))// 返回-11
ceil():把小数向上舍入成整数,如果是负数相当于vbscript
中的Fix()函数
例:
alert(Math.ceil(10.1))//返回11
alert(Math.ceil(10.5))//返回11
alert(Math.ceil(10.9))//
返回11
alert(Math.ceil(-10.1))//返回-10
alert(Math.ceil(-10.5))//返回-10
alert(Math.ceil(-10.9))//
返回-10
floor():把小数向下舍入成整数 ,相当于vbscript中Int(
)
例:
alert(Math.floor(10.1))//返回10
alert(Math.floor(10.5))//返回10
alert(Math.floor(10.9))//
返回10
alert(Math.floor(-10.1))//返回-11
alert(Math.floor(-10.5))//返回-11
alert(Math.floor(-10.9))//
返回-11
round():进行四舍五入 ,相当于vbscript中round( )注意负数
例:
alert(Math.round(10.1))//返回10
alert(Math.round(10.5))//返回11
alert(Math.round(10.9))// 返回11
alert(Math.round(-10.1))//返回-10
alert(Math.round(-10.50))//返回-10
alert(Math.round(-10.51))//返回-11
alert(Math.round(-10.9))// 返回-11
相关文章推荐
- Javascript Math ceil()、floor()、round()三个函数的区别
- 实现JavaScript 的Math.round,Math.ceil,Math.floor函数功能 CodeWars 打怪日记
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- ThinkPHP 学习笔记<一>:ThinkPHP常用函数说明
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- Javascript Math ceil()、floor()、round()三个函数的区别
- <转> js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结
- javascript Math ceil()、floor()、round()三个函数的区别
- javascript中的Math.round()和Math.floor()函数Math.ceil()的区别
- javascript中的Math.ceil() 、Math.floor() 、Math.round() 三个函数
- Delphi 常用函数(数学函数)round、trunc、ceil和floor
- C++库常用函数一览(<string><cctype><algorithm><cmath><cstdlib><iomanip><numeric>)
- javascript 的 Math.ceil()、Math.floor()、Math.round()