当前位置:编程学习 > JAVA >>

Javascript Math ceil()、floor()、round()三个函数的区别

Javascript Math ceil()、floor()、round()三个函数的区别
Round是四舍五入的。。。Ceiling是向上取整。。float是向下取整
 
-
ceil():将小数部分一律向整数部分进位。
如:
 
Math.ceil(12.2)//返回13
Math.ceil(12.7)//返回13
Math.ceil(12.0)// 返回12
 
floor():一律舍去,仅保留整数。
如:
 
Math.floor(12.2)// 返回12
Math.floor(12.7)//返回12
Math.floor(12.0)//返回12
 
round():进行四舍五入
如:
 
Math.round(12.2)// 返回12
Math.round(12.7)//返回13
Math.round(12.0)//返回12
补充:web前端 , JavaScript ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,