1、double java.lang.Math.floor(double a)

返回最大的double值(在正无穷方向上最接近的)小于或等于参数a的一个数学意义上的整数,特例:

如果参数值等于数学上的整数,则返回结果与参数值相同

如果参数是NaN(非数值)或是无穷或是+0或是-0,则返回值和参数值相同

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. Special cases:

If the argument value is already equal to a mathematical integer, then the result is the same as the argument.

If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.

Math.floor(2.0)=2.0
Math.floor(2.1)=2.0
Math.floor(2.5)=2.0
Math.floor(2.9)=2.0
Math.floor(-2.0)=-2.0
Math.floor(-2.1)=-3.0
Math.floor(-2.5)=-3.0
Math.floor(-2.9)=-3.0
2、double java.lang.Math.ceil(double a)
返回最小的double值(在负无穷方向最接近的)大于或等于参数a的一个数学意义上的整数,特例:
如果参数值已经等于一个数学意义上的整数,则返回结果与参数相同
如果参数是NaN(非数值)或者是无穷,或是+0,-0,则返回结果与参数相同
如果参数值小于0或大于-1.0

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer. Special cases:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
  • If the argument value is less than zero but greater than -1.0, then the result is negative zero.
Math.ceil(2.0)=2.0
Math.ceil(2.1)=3.0
Math.ceil(2.5)=3.0
Math.ceil(2.9)=3.0
Math.ceil(-2.0)=-2.0
Math.ceil(-2.1)=-2.0
Math.ceil(-2.5)=-2.0
Math.ceil(-2.9)=-2.0

double java.lang.Math.rint(double a)

Returns the double value that is closest in value to the argument and is equal to a mathematical integer. If two double values that are mathematical integers are equally close, the result is the integer value that is even. Special cases:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Math.rint(2.0)=2.0
Math.rint(2.5)=2.0
Math.rint(2.6)=3.0
Math.rint(2.9)=3.0
Math.rint(-2.0)=-2.0
Math.rint(-2.5)=-2.0
Math.rint(-2.6)=-3.0
Math.rint(-2.9)=-3.0

long java.lang.Math.round(double a)

Returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. In other words, the result is equal to the value of the expression:

(long)Math.floor(a + 0.5d)

Special cases:

  • If the argument is NaN, the result is 0.
  • If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE.
  • If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.
Math.round(2.0)=2
Math.round(2.5)=3
Math.round(2.6)=3
Math.round(2.9)=3
Math.round(-2.0)=-2
Math.round(-2.5)=-2
Math.round(-2.6)=-3
Math.round(-2.9)=-3

转载于:https://www.cnblogs.com/tobebrave/p/4178430.html

Java语言中小数的取整相关推荐

  1. 为什么python除法结果会有小数点0_关于python:为什么整数除法会在许多脚本语言中向下取整?...

    在我测试过的语言中,- (x div y )不等于-x div y: 我已经在Python中测试了//,在Ruby中测试了/,在Perl 6中测试了div: C具有类似的行为. 该行为通常是按照规范进 ...

  2. C语言中四种取整方式、取余/取模的运算以及负数取模的问题

    零向取整.负无穷向取整.正无穷向取整.四舍五入取整 如果将一个浮点数赋值给整形,只会保存整数位: 这种取整方式为零向取整,C语言默认采用的是这种方式 C语言中也有对应的零向取整函数: 同理还有一种函数 ...

  3. MATLAB中对小数进行取整处理

    1.matlab 小数怎么转化整数? 根据你的需要,可以使用fix.ceil.floor.round这几个函数. 这几个函数的取整规则不同:fix只保留整数部分,ceil向上取整,floor向下取整, ...

  4. python两位小数向上取整函数_python3中的函数如何实现小数向上取整

    python3中的函数如何实现小数向上取整 发布时间:2020-11-12 09:25:21 来源:亿速云 阅读:82 作者:小新 这篇文章将为大家详细讲解有关python3中的函数如何实现小数向上取 ...

  5. java语言中声明布尔型_【Java初探02】——Java语言基础

    本篇博文就Java语言的一些基本元素进行一些记录和阐述,主要讲解一下Java语言的一些基本构成元素和Java的主类结构. Java语言基础的大致组成 java主类结构 基本的数据类型 变量与常量 运算 ...

  6. Java快速入门学习笔记2 | Java语言中的基本类型

    有人相爱,有人夜里开车看海,有人却连LeetCode第一题都解不出来!虽然之前系统地学习过java课程,但是到现在一年多没有碰过Java的代码,遇到LeetCode不知是喜是悲,思来想去,然后清空自己 ...

  7. Java语言中的生僻知识

    最近有一首名叫<生僻字>的流行歌曲火遍大江南北,创作者给佶屈聱牙的生僻字,配上了优美明快的旋律,竟然让歌曲变得琅琅上口.悦耳动听起来,平时不太常见的拒人于千里之外的这些汉字也不再那么陌生, ...

  8. python中math.ceil是什么意思_python中的数字取整(ceil,floor,round)概念和用法

    python中的数学运算函数(ceil,floor,round)的主要任务是截掉小数以后的位数.总体来说 就是取整用的.只是三者之间有微妙的区别: floor() :把数字变小 ceil() : 把数 ...

  9. Java 语言中十大“坑爹”功能!

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源:https://www.sohu.com/a/35 ...

最新文章

  1. 离不开的“微服务”架构,脱不开的RPC细节(收藏)
  2. 球迷福利!Next VR本周将直播三场ICC比赛
  3. 移动端python开发_python前端之移动端库、框架及自动化和优化
  4. 很慢怎么办_手机信号满格,网速却很慢怎么办?3招教你一键恢复网络
  5. android无法自动旋屏,Android 手动设置屏幕方向后不能自动转屏问题
  6. stc89c52开发板遥控器解码 红外线发射 内置 eeprom 存储 串口显示编码
  7. 工作笔记-新系统安装deb文件失败
  8. html设置功能区菜单,html – 具有“3D”效果的功能区
  9. 最新android studio创建项目,创建项目  |  Android 开发者  |  Android Developers
  10. exchange功能在线测试
  11. 从零开始,我用了两年半逆袭秋招!
  12. 稳压二极管型号对应电压表
  13. python 双色球 大乐透 5注随机选号
  14. 网站改造为百度智能小程序教程,适合所有网站封装
  15. python调用dll文件
  16. 知识星球问答精选(附五一赠书活动)
  17. 2008'中国地理信息系统优秀工程公示
  18. 《结网》@互联网产品经理改变世界 读后感
  19. SOT-23封装如何查找元件型号
  20. MySql打开局域网及广域网端口

热门文章

  1. 安卓怎么连接服务器的数据库文件,安卓怎么连接服务器的数据库文件
  2. php 7.0 编译安装mysql_源码编译安装php7.0.5
  3. 迭代法求解线性方程组
  4. EOJ Monthly 2018.11 D. 猜价格
  5. centos/linux扩容Swap分区
  6. setState 是异步的
  7. Vue 路由 过渡动效 数据获取
  8. FileZilla Server简介及使用说明
  9. c#大文件读取和写入数据库
  10. 1.2.3 TCP/IP参考模型和五层参考模型