Math.round、Math.floor、Math.ceil 区别
1、Math.round() 按照四舍五入的方式返回值
例如:Math.round(9.5)=10
Math.round(9.4)=9
2、Math.floor()返回最小整数
例如:Math.floor(9.5)=9
Math.floor(9.2)=9
3、Math.ceil()返回最大整数
例如: Math.ceil(9.1)=10
Math.ceil(9.5)=10
Math.round、Math.floor、Math.ceil 区别的更多相关文章
- 关于Math类的round、floor、ceil三个方法
一.Math类这三个方法的简介 1.round():取最接近的值. 对于这个方法,查看源代码,其实现如下: public static long round(double a) { if (a != ...
- Math.floor,Math.ceil,Math.rint,Math.round用法
一.Math.floor函数讲解 floor原意:地板.Math.floor函数是求一个浮点数的地板,就是求一个最接近它的整数,它的值小于或等于这个浮点数.看下面的例子: package com.qi ...
- int和integer;Math.round(11.5)和Math.round(-11.5)
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
- Java Math.round()函数小结
Math类中提供了三个与取整有关的方法:ceil,floor,round,这些方法的作用于它们的英文名称的含义相对应,例如:ceil的英文意义是天花板,该方法就表示向上取整,Math.ceil(1 ...
- Math.round()
在 JAVA 中四舍五入采用 Math.round(T a) 函数,函数返回的是一个 long 类型的长整型,参数 a 可以是 double 也可以是 float. 查看 JDK 源码: public ...
- Javascript四舍五入(Math.round()与Math.pow())
代码 Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ ...
- 【JAVA】Math.Round()函数常见问题“四舍5入”
java.lang.Math.Round()使用时候,处理方式整理,方便以后查找 /** * 测试函数 2014-01-10 */ public class TestMath { pu ...
- 关于Math.round()方法
先上结论: 1.参数的小数点后第一位<5,运算结果为参数整数部分. 2.参数的小数点后第一位>5,运算结果为参数整数部分绝对值+1,符号(+ or -)不变. 3.参数的小数点后第一位=5 ...
- Math.round(11.5)
Math.round(-11.5); Math.round(11.5); 经常看到这句代码,特意来总结一下. 查阅资料一直有人说是"四舍六入五成双",四舍六入没错,不过遇到正负数的 ...
- Javascript Math.ceil()与Math.round()与Math.floor()区别
Math.ceil()向上舍入 1 2 3 alert(Math.ceil(20.1)) //输出 21 alert(Math.ceil(20.5)) //输出 21 alert(Math.ceil( ...
随机推荐
- HDU 6069 Counting Divisors (素数+筛法)
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- zrender源码分析4--初始化Painter绘图模块2
入口2: 渲染 // zrender_demo.html zr.render(); // zrender.js /** * 渲染 * * @param {Function} callback 渲染结束 ...
- JavaScript语言精粹 笔记02 函数
函数函数对象函数字面量调用参数返回异常给类型增加方法递归作用域闭包回调模块级联套用记忆 函数 1 函数对象 在JS中函数就是对象.对象是“名/值”对的集合并拥有一个连接到原型对象的隐藏连接.对象字 ...
- LinearLayout属性用法和源码分析
转载自:http://www.jianshu.com/p/650c3fd7e6ab 一. LinearLayout的属性和用法 LinearLayout对于开发来说,是使用最常用的布局控件之一,但 ...
- Python 3 Mysql 增删改查
import pymysql import datainfo import time #获取参数 host = datainfo.host username = datainfo.username p ...
- 【扫盲贴】为什么屏幕分辨率是 640x480
本文原地址:http://www.easyx.cn/skills/View.aspx?id=172 常见的屏幕分辨率很奇怪,为什么总用一些不零不整的数字?比如以前最常见的分辨率是 640x480,当初 ...
- Javascript与数据结构系列(二)——队列的实现
队列实现 使用数组来实现队列看起来顺理成章.JavaScript 中的数组具有其他编程语言中没有的优点, 数组的 push() 方法可以在数组末尾加入元素,shift() 方法则可删除数组的第一个元素 ...
- vmware中安装centos 6.7
centos 6.7 软件下载地址:http://b.mirrors.lanunion.org/CentOS/6.7/isos/i386/ 引用:http://www.cnblogs.com/sees ...
- java学习(三)数组
一维数组的定义格式: int[] a; //定义一个int类型的数组a变量 int a[]; //定义一个int类型的a数组变量 初始化一个int类型的数组 int[] arr = new i ...
- MVC4 Action 方法的执行
1. ActionInvoker 的执行: 在MVC 中 包括Model绑定与验证在内的整个Action的执行是通过一个名为ActionInvoker的组件来完成的. 它同样具有 同步/异步两个版本 ...