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. 使用U盘安装Linux最美桌面发行版Elementary OS 及常用开发环境配置(JDK,Redis,MySQL,Docker,IDEA,STS)

    前言 假期在家无聊,刚好把六年前的一台笔记本电脑利用起来,原来电脑虽然说配置说不上古董机器,但是运行win系统感觉还是不流畅,所幸给换成Linux桌面版系统,在网上查阅了很多,Linux桌面系统要么推 ...

  2. STM32CubeIDE printf 串口重定向

  3. Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3

    前端导入静态页面的时候有一个报错,主要问题是冲突了 Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or hi ...

  4. NO24 第三关--企业面试题

    [考试目的] 1.学生课后复习及预习情况. 2.未来实际工作中做人做事能力. 3.沟通及口头表达能力. [口头表达技能考试题] 1.描述linux的开机到登陆界面的启动过程(记时2分钟) *****L ...

  5. s2010编译C++ 链栈的使用

    // CTest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include &l ...

  6. centos安装sass环境必看

    首先了解一下  sass是什么?! sass号称“世界上最成熟.最稳定.最强大的专业级css扩展语言” ,sass基于于Ruby语言开发而成,因此安装sass前需要安装Ruby, 1.安装ruby y ...

  7. android侧滑效果(引用官方网站提供的API文件)

    原文地址:http://www.cnblogs.com/android100/p/android-SlidingMenu.html 在新浪微博和唱吧里面都有看到android的侧滑效果,于是想要学习一 ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-cog

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  9. c#使用Socket实现局域网内通信

    服务器端代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Da ...

  10. vlc rtsp 服务器脚本

    set VLC="C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" set VIDEO="D:\BaiduYunDownload\ ...