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方法的更多相关文章

  1. Matlab中的取整-floor,ceil,fix,round

    FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...

  2. 关于Matlab里面的四个取整(舍入)函数:Floor, Ceil, Fix, Round的解释(转)

    转自http://blog.sina.com.cn/s/blog_48ebd4fb010009c2.html   floor:朝负无穷方向舍入 B = floor(A) rounds the elem ...

  3. C/C++四种取整函数floor,ceil,trunc,round

    处理浮点数操作常用到取整函数,C/C++提供了四种取整函数 floor函数 floor函数:向下取整函数,或称为向负无穷取整 double floor(double x); floor(-5.5) = ...

  4. 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() 语法 ...

  5. Math类的三个方法比较: floor() ceil() round()

    public class Test { public static void main(String[] args) { double d1 = 3.4, d2 = 3.6; //正数 double ...

  6. matlab中fix, floor, ceil, round 函数的使用方法

    转载: https://www.ilovematlab.cn/thread-91895-1-1.html Matlab取整函数有: fix, floor, ceil, round.具体应用方法如下: ...

  7. MATLAB中取整函数(fix, floor, ceil, round)的使用

    MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans = 3    -3(2)floor(x):不超过x 的最大整数.(高斯取整) & ...

  8. paper 68 :MATLAB中取整函数(fix, floor, ceil, round)的使用

    MATLAB取整函数 1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans =      3    -3 (2)floor(x):不超过x 的最大整数.(高 ...

  9. php四舍五入函数(floor、ceil、round与intval)

    原文链接:php四舍五入函数(floor.ceil.round与intval) PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法 ...

随机推荐

  1. SystemVerilog Assertion 设计、调试、测试总结(3)

    上两篇主要是讲述断言的概念,基本语法,总结等等 这一篇主要是以PPT的形式展示各个场景下关于断言的应用. 为了在设计中加入断言的功能,因此需要写一个DUT.如下: `define `define fr ...

  2. R语言 使用rmarkdown写代码

    1.如果是第一次新建markdown文件,需要在有网的条件下,因为要下载一个包才能用markdown 2.为什么使用rmarkdown 使用markdown不仅可以边调试边运行,还可以一次性将所调试好 ...

  3. Windows篇:文件对比软件->"DiffMerge"

    文件对比软件->"DiffMerge" DiffMerge是什么? 如果没有DiffMerge! 想想一下,有两篇10000字的文章,找不同,眼睛都要看花吧.有了DiffMe ...

  4. 防止SQL注入的登录页面

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/T ...

  5. 12541:TNS无监听状态

    上次在项目上遇见数据库报这个问题,然后网上几乎都是让重新进行配置数据库.配置多次之后还是无效,最后找到了问题的根源. 使用的是Oracle数据库,用PLSQL登录报的这个错误. 在计算机全局搜索:li ...

  6. day02-Python运维开发基础

    1. Number 数据类型 2. 容器数据类型-字符串 """ 语法: "字符串" % (值1,值2 ... ) 占位符: %d 整型占位符 %f ...

  7. web.xml CharacterEncodingFilter

    <!-- SpingMVC字符集过滤器 --> <filter> <filter-name>characterEncodingFilter</filter-n ...

  8. maven知识结构笔记

    1.什么是maven Maven 翻译为"专家"."内行",是 Apache 下的一个纯 Java 开发的开源项目.基于项目对象模型(缩写:POM)概念,Mav ...

  9. B. Misha and Changing Handles

    B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input ...

  10. 用四种方法将两个AJAX改为同步

    用四种方法将两个AJAX改为同步 Promise.Generator函数.yield.async/await 相关 今有一题,题目为: 现有ajax1()和ajax2(),用于快速初始化CODE1和C ...