Math ceil()、floor()、round()方法
来源:互联网 发布:软件研发工作流程 编辑:程序博客网 时间:2024/05/16 12:46
Math ceil()、floor()、round()方法
Math.ceil()
功能:对一个数进行上取整。
语法:Math.ceil(x)
参数:
x:一个数值。
返回值:返回大于或等于x,并且与之最接近的整数。
注:如果x是正数,则把小数“入”;如果x是负数,则把小数“舍”。
例:
<script type="text/javascript">
document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );
</script>
输出结果为:
2, 2, -1, -1
Math.floor()
功能:对一个数进行下取整。
语法:Math.floor(x)
参数:
x:一个数值。
返回值:返回小于或等于x,并且与之最接近的整数。
注:如果x是正数,则把小数“舍”;如果x是负数,则把小数“入”。
例:
<script type="text/javascript">
document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) );
</script>
输出结果为:
1, 1, -2, -2
Math.round()
功能:四舍五入取整。
语法:Math.round(x)
参数:
x:一个数值。
返回值:与x最接近的整数。
例:
<script type="text/javascript">
document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );
</script>
输出结果为:
1, 2, -1, -2
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xiaxiaorui2003/archive/2009/12/10/4980076.aspx
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- Math.round ceil floor
- Math ceil(),floor(),round()方法的使用
- Java Math的floor、ceil、round方法
- JavaScript Math对象 ceil()、floor()、round()方法
- Math.ceil()和Math.floor()、Math.round()
- Math.round|Math.floor|Math.ceil区别
- Math.floor,Math.round,Math.ceil
- Math.round, Math.ceil 和 Math.floor
- Math.floor()/Math.ceil()/Math.round()
- Math.ceil、Math.floor、Math.round用法
- 关于java中的Math.round()方法floor,ceil方法
- java中Math方法的ceil,floor,round方法
- Java Math类的三个方法ceil,floor,round
- java Math的round,floor,ceil,IEEEremainder 方法总结
- Struts2拦截了Servlet的请求解决
- 转:英语老师永远都不会告诉你的经典网站
- 迷茫的大学生,清醒吧
- Ext智能提示 - JSEclipse(Eclipse插件)
- 分区设置损坏
- Math ceil()、floor()、round()方法
- 监控和剖析数据库操作 -- P6Spy、SQL Profiler、IronTrack SQL(网络
- DB2 查询统计信息的命令
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回
- XP系统的超级管理员安全忠告
- ibatis 查询数据的设置
- ibatis 如何利用自增主键插入数据库
- 没天理啊···
- 【解惑】想进大公司学生的困惑