Java取整数
来源:互联网 发布:淘宝开店需要交1000吗 编辑:程序博客网 时间:2024/05/12 06:21
Math ceil()、floor()、round()方法
转载地址:http://blog.csdn.net/xiaxiaorui2003/article/details/6481034
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>
document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );
</script>
输出结果为:
document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) ); 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>
document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) );
</script>
输出结果为:
document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) ); 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>
document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );
</script>
输出结果为:
document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) ); 1, 2, -1, -2
阅读全文
0 0
- Java取整数
- jsp页面取整数 和Java页面取整数
- java四舍五入,取小于这个数的最大整数,取大于这个数的最小整数
- java-随机取0-100之间的整数
- 关于java中整数类型数据的取值范围
- JavaRuntime内存 && Java整数类型和取值范围
- js取整数、取余数
- 怎样取整数?
- js取整数四舍五入
- 整数向上取整
- js取整数四舍五入
- js取整数
- 大整数取模
- 整数取反相关
- 关于Freemarker 取整数
- js除法取整数
- js 取整数
- 整数取反
- Feign的简单应用总结
- 全氢聚硅氮烷液体涂料材料
- 华为OJ----汽水瓶数
- java Runtime.getRuntime().exec 调用系统脚本/命令注意事项
- 解决win10无法安装framework3.5问题
- Java取整数
- HDU 3487 Play with Chain [平衡树splay]
- Java引用外部字体即自定义字体文件
- 梦想CAD控件 2017.7.19最新更新
- 鸡兔同笼问题
- Java类与对象
- #Unity自建塔防游戏知识点
- 最小生成树——Kruskal算法
- C++ string