数学对象Math ceil()、floor()、round()方法
|
Math.ceil()
|
|
功能:对一个数进行上取整。
语法:Math.ceil(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) ); 2, 2, -1, -1
|
|
Math.floor()
|
|
功能:对一个数进行下取整。
语法:Math.floor(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) ); 1, 1, -2, -2
|
|
Math.round()
|
|
功能:四舍五入取整。
语法:Math.round(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) ); 1, 2, -1, -2
|
原文链接:http://blog.csdn.net/xiaxiaorui2003/article/details/6481034
数学对象Math ceil()、floor()、round()方法的更多相关文章
- javascript中Math ceil(),floor(),round()三个函数的对比
Math.ceil()执行的是向上舍入 Math.floor()执行向下舍入 Math.round()执行标准舍入 一下是一些补充: ceil():将小数部分一律向整数部分进位. 如: Math.ce ...
- C语言中几个常用数学计算函数ceil(), floor(), round()的用法
最近在实现算法的过程中,遇到了使用几个数学计算函数,感觉挺有意思,就记下来 方便以后使用. ceil(x)返回不小于x的最小整数值(然后转换为double型). floor(x)返回不大于x的最大整数 ...
- Math类的round方法小解
在Math类中有三个关于“四舍五入”的静态方法(ceil,floor,round): ① Math.ceil(number) 向上取整,Math.ceil(11.2) 结果:12 ...
- JAVA除法保留小数点后两位的两种方法 Java Math的 floor,round和ceil的总结
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下 ...
- Math对象(min()-max()-ceil()-floor()-round()和abs())
1.Math.min() 功能:求一组数的最小值,返回值:Number 如果里面有非数字则返回NaN 2.Math.max() 功能:求一组数的最大值,返回值:Number 3.Math.ceil() ...
- Math中floor,round和ceil的区别
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数(当-1.5时可见,四舍五入后得到的结果不是我们期待的,解决办法是先对他取绝对值,然后在用round方法) r ...
- Java Math的 floor,round和ceil的总结
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下 ...
- Java Math的 floor,round和ceil
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数 round方法,它表示"四舍五入",算法为Math.floor(x+0.5),即将原来的 ...
- java floor,ceil和round方法
Math.floor():返回值是double类型的,返回的是不大于它的最大整数 举例: double x = Math.floor(5.8); System.out.println(x); //输出 ...
随机推荐
- 编写一个程序对Largest函数进行测试,找出一组数据的最大值
源程序代码: import java.util.Scanner; public class findmax { public static void main(String[] args) { // ...
- 动态WebService方法
[转] 调用Webservice的方法一般是通过右击项目-->添加服务引用-->输入Webservice地址-->前往-->确定,这样可以顺利调用服,但是需要注意的一点是:如果 ...
- 中文unicode范围及unicode编解码
中文unicode范围 : [\u4e00-\u9fa5] 普通字符串可以用多种方式编码成Unicode字符串,具体要看你究竟选择了哪种编码:unicodestring = u"Hello ...
- linux下分卷tar.bz文件的合并并解压缩
linux下分卷tar.bz文件的合并并解压缩 例: linux.tar.bz2.001;linux.tar.bz2.002;linux.tar.bz2.003; 首先 cat linux.tar.b ...
- shell export
export命令将使系统在创建每一个新的shell时定义这个变量的一个拷贝.这个过程称之为变量输出. 在脚本中export,跟在终端export原理一样. 他们都是一个子shell. http://b ...
- 使用jaxp对比xml进行SAX解析
package cn.itcast.sax; import java.io.IOException; import javax.xml.parsers.ParserConfigurationExcep ...
- java cmd 命令
java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后关闭命令窗口. cmd /k dir 是执行完d ...
- Kung fu
1. originPeople in Primitive society(原始社会)in order to survive,they have to hunt for food efficiently ...
- 使用eclipse上传项目到开源中国代码托管Git@osc教程
创建项目 安装EGit插件 没有的话看下图 生成公钥 注册git账号 新建git项目 添加公钥 建立本地代码库 本文章版权归博主所有,如需转载请私信.
- Azure磁盘的吞吐量测试
Azure的高级存储具有吞吐量大,延迟低的特点,非常适合时间关键型的应用程序(如SQL Server, Oracle, Redis等). 但高级存储同时具有价格高的特点,用户往往对其实际的性能数据较为 ...