数学对象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); //输出 ...
随机推荐
- 值得推荐的C/C++框架和库 (真的很强大)
值得学习的C语言开源项目 - 1. Webbench Webbench是一个在Linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的 ...
- NeHe OpenGL教程 第二课:多边形
前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线教程的编写,以及yarn的翻译整理表示感谢 ...
- Shell 重定向 &>file,2>&1,1>&2 的区别
Shell上:0表示标准输入1表示标准输出2表示标准错误输出> 默认为标准输出重定向,与1>相同2>&1 意思是 把标准错误输出重定向到标准输出1>&2 意思是 ...
- php 消息队列
本消息队列用于linux下,进程通信 #根据路径和后缀创建一个id $key = ftok(__DIR__, 'R'); #获取队列中的消息 $q = msg_get_queue($key); #删除 ...
- BigDecimal的equals
BigDecimal testA = new BigDecimal(79); BigDecimal testB = new BigDecimal("79.00"); System. ...
- code md5
using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptograph ...
- 安装ipython import path error
sudo pip install ipython --upgrade # 升级 版本兼容性问题,升级到最新版本的ipython 后,会报错 from pickleshare import Pickle ...
- (转)关于rdlc报表的数据源
rdlc 报表字符类数据分为文本数据和表数据,区别就在于文本数据只有一个,表数据可以有多行,然而有很多数据只需要一个传入就可以比如打印某个用户的基本信息,很多信息都是唯一的,如果此时报表传入的数据 ...
- MongoDB Tool
robomongo MongoBooster: [推薦]MongoChef:http://3t.io/mongochef/download/ MongoVUE 是个比较好用的MongoDB客户端,不过 ...
- SelectedValue 失效
/// <summary> /// 绑定代表下拉选项 /// </summary> public void BindOwnerDataII(string unitId, str ...