Math中floor,round和ceil的区别
floor 返回不大于的最大整数
round 则是4舍5入的计算,入的时候是到大于它的整数(当-1.5时可见,四舍五入后得到的结果不是我们期待的,解决办法是先对他取绝对值,然后在用round方法)
round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.round(-11.5)的结果为-11。
ceil 则是不小于他的最小整数
example:
|
src value |
Math.floor |
Math.round |
Math.ceil |
|
1.4 |
1 |
1 |
2 |
|
1.5 |
1 |
2 |
2 |
|
1.6 |
1 |
2 |
2 |
|
-1.4 |
-2 |
-1 |
-1 |
|
-1.5 |
-2 |
-1 |
-1 |
|
-1.6 |
-2 |
-2 |
-1 |
Math.floor(1.4)=1.0
Math.round(1.4)=1
Math.ceil(1.4)=2.0
Math中floor,round和ceil的区别的更多相关文章
- JAVA除法保留小数点后两位的两种方法 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),即将原来的数字加上0.5后再向下 ...
- Java Math的 floor,round和ceil
floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数 round方法,它表示"四舍五入",算法为Math.floor(x+0.5),即将原来的 ...
- 基础笔记1(进制,浮点,递归,floor,round和ceil)
1,进制默认是十进制 0开头 8进制 0x 16进制 0b 2进制 2,long 的范围是19位数字.int范围是21亿左右,short 是三万二千左右. 超过int范围的long类型 ...
- oracle中floor函数和to_number函数区别
oracle中floor函数没有值默认是0,number函数没有值默认是空
- Math中的floor,round和ceil方法总结
floor向下取整,返回不大于的最大整数 Math.floor(1.4)=1.0ceil向上取整,返回不小于的最小整数 Math.ceil(1.4)=2.0round 四舍五入,将原来的数字加入0 ...
- php取整函数floor(),round(),intval(),ceil()
ceil -- 进一法取整说明float ceil ( float value )返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float, ...
- Math类中round、ceil和floor方法的功能
Java中的Math工具类用来完成除+.-.*./.%等基本运算以外的复杂运算,位于java.lang包下,Math类的构造器全是私有的(private),因此无法创建Math类的对象,Math类的方 ...
- C++中的 Round(),floor(),ceil()
2.1 2.6 -2.1 -2.6floor : 不大于自变量的最大整数 2 ...
随机推荐
- CSS样式设置记录
在不懂php和wordpress的情况下,需要按照样式内容用php+wordpress+mysql做个网站,网页上有许多样式需要设置,包括颜色字体等要跟要求一致,记录下今天的结果. <div i ...
- 设置浏览器使用的dom模式为IE7
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>设置浏览器使用的dom模式为 ...
- lucene字典实现原理——FST
转自:http://www.cnblogs.com/LBSer/p/4119841.html 1 lucene字典 使用lucene进行查询不可避免都会使用到其提供的字典功能,即根据给定的term找到 ...
- 我们无法找到服务器加载工作簿的数据模型"的 SharePoint 网站,当您刷新 Excel 2013 工作簿中的数据透视表时出错
假定您使用 Analysis Services 源在 Microsoft Excel 2013 中创建数据透视表.将 Excel 工作簿上载到 Microsoft SharePoint 网站中.当您尝 ...
- 一道数学题 hduacm 5144
题目大意: 一直初速度v和抛出速度h 求标枪抛出的最远距离: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5144 显然 d=v/g*sqrt( ...
- JS点击复制
<!DOCTYPE html><html><head> <script type="text/javascript"> functi ...
- bzoj 1877: [SDOI2009]晨跑
#include<cstdio> #include<iostream> #include<cstring> #define M 6009 #define inf 2 ...
- dancing link模板
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #i ...
- java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError at com.csdhsm.compiler.test.DevTest.testReadInput(DevTest.java ...
- 【C语言学习】-02 分支结构
本文目录: 一.BOOL布尔类型 二.关系运算符 三.逻辑运算符 四.if语句 五.枚举类型 六.switch语句 一.BOOL布尔类型 BOOL数据类型,是一种表示非真即假的数据类型,布尔类型的变量 ...