java floor,ceil和round方法
Math.floor():返回值是double类型的,返回的是不大于它的最大整数
举例:
double x = Math.floor(5.8);
System.out.println(x); //输出结果:5.0
double x = Math.floor(-2.5);
System.out.println(x); //输出结果:-3.0
Math.ceil():返回值是double类型的,返回的是不小于它的最小整数
举例:
double x = Math.ceil(5.8);
System.out.println(x); //输出结果:6.0
double x = Math.ceil(-2.5);
System.out.println(x); //输出结果:-2.0
Math.round():返回值是 int/long 类型的,返回的是四舍五入或四舍六入后的整数
(或者理解为Math.floor(x+0.5):在原来的数上+0.5再向下取整)
举例:
int x = Math.round(1.6);
System.out.println(x); //输出结果:2
int x = Math.round(1.3);
System.out.println(x); //输出结果:1 int x = Math.round(-1.6);
System.out.println(x); //输出结果:-2
int x = Math.round(-1.5);
System.out.println(x); //输出结果:-1
java floor,ceil和round方法的更多相关文章
- Matlab中的取整-floor,ceil,fix,round
FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...
- 关于Matlab里面的四个取整(舍入)函数:Floor, Ceil, Fix, Round的解释(转)
转自http://blog.sina.com.cn/s/blog_48ebd4fb010009c2.html floor:朝负无穷方向舍入 B = floor(A) rounds the elem ...
- C/C++四种取整函数floor,ceil,trunc,round
处理浮点数操作常用到取整函数,C/C++提供了四种取整函数 floor函数 floor函数:向下取整函数,或称为向负无穷取整 double floor(double x); floor(-5.5) = ...
- JavaScript中的内置对象-8--3.Math-Math对象的方法-min()- max()- ceil() - floor()- round()- abs(); Math对象的random()方法;
JavaScript内置对象-3.Math(数值) 学习目标 1.掌握Math对象的方法: min() max() ceil() floor() round() abs() Math.min() 语法 ...
- Math类的三个方法比较: floor() ceil() round()
public class Test { public static void main(String[] args) { double d1 = 3.4, d2 = 3.6; //正数 double ...
- matlab中fix, floor, ceil, round 函数的使用方法
转载: https://www.ilovematlab.cn/thread-91895-1-1.html Matlab取整函数有: fix, floor, ceil, round.具体应用方法如下: ...
- MATLAB中取整函数(fix, floor, ceil, round)的使用
MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3 -3(2)floor(x):不超过x 的最大整数.(高斯取整) & ...
- paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用
MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3 -3 (2)floor(x):不超过x 的最大整数.(高 ...
- php四舍五入函数(floor、ceil、round与intval)
原文链接:php四舍五入函数(floor.ceil.round与intval) PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法 ...
随机推荐
- redis学习笔记-04:redis五大数据结构类型
redis的命令大全网站:http://redisdoc.com/ 一.redis五大数据类型 1.String(字符串).Hash(哈希,类似Java里的Map).List(列表).Set(集合)和 ...
- 【拒绝挂分】盘点蒟蒻ghy的各种sb错误
1.m与n打反(打错) NOIPd2t2 50变15爽不爽啊.jpg 某次信心赛四道sb题里面最sb的一道 sort里面的m打成n 100变40爽不爽啊.jpg(还有40我真的谢谢您了 2.没开lon ...
- 「POI2015」KIN
传送门 Luogu 解题思路 想要做这道题,只要会维护区间最大子段和就好了. 而这个可以用线段树维护模板点这里 对于重复的情况,我们可以对每一个位置记一个前驱表示和当前位置种类相同的前一个位置. 然后 ...
- 小程序行内元素且有border的情况下,根据文字宽度自动调节元素宽度
比如认识成都: <view style="display: flex;align-items: center;"> <text class="cityV ...
- Lesson 2 Spare that spider
How much of each year do spiders killing insects? Why, you may wonder, should spiders be our friends ...
- 三 Road
3—5年程序员的发展和出路在哪里? 是继续做技术人,还是向管理者发力?是继续留在大公司,还是转投潜力小公司?如果没有核心竞争力,入行一两年的新程序员朋友是可以替代你大部分工作的,而且薪资还低,要怎么办 ...
- P1086 就不告诉你
转跳点:
- PAT (Advanced Level) 1128~1131:1128N皇后 1129 模拟推荐系统(set<Node>优化) 1130 中缀表达式
1128 N Queens Puzzle(20 分) 题意:N皇后问题.按列依次给定N个皇后的行号,问N个皇后是否能同时不存在行冲突.列冲突和主副对角线冲突. 分析: 1.根据题意一定不存在列冲突,所 ...
- POJ 3436:ACM Computer Factory 网络流
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6247 Accepted: 2 ...
- GoJS实例3
复制如下内容保存到空白的.html文件中,用浏览器打开即可查看效果 <!DOCTYPE html> <html> <head> <meta charset=& ...