容易混淆的某些Math方法说明
1. Math.round
返回最接近的整数值,实际上就是我们说的对小数进行四舍五入。
/**
* 返回最接近参数的long
*/
static long round(double a)
/**
* 返回最接近参数的int
*/
static int round(float a)
实例如下:
- Math.round(8.1): 8
- Math.round(8.4): 8
- Math.round(8.5): 9
- Math.round(8.9): 9
- Math.round(-8.1): -8
- Math.round(-8.4): -8
- Math.round(-8.5): -8 // 负数与整数不同。 当第一位小数小于等于5的时候进行进位,因此得到 -8
- Math.round(-8.9): -9 // 当第一位小数大于5时,进行舍去。-9是小于-8的下一个整数,因此得到-9
2. Math.floor
实际上就是返回不大于参数的最大整数值的double类型。
/**
* 返回某个最大的double值。该值小于等于参数,并等于某个整数。
*/
static double floor(double a)
实例如下:
Math.floor(8.9): 8.0
Math.floor(8.1): 8.0
Math.floor(-8.1): -9.0
Math.floor(-8.9): -9.0
3. Math.ceil
和Math.floor刚好相反,返回的是不小于参数的最小整数值的double类型。
/**
* 返回最小的(最接近负无穷大)double 值,该值大于等于参数,并等于某个整数。
*/
static double ceil(double a)
实例如下:
Math.ceil(8.9): 9.0
Math.ceil(8.1): 9.0
Math.ceil(-8.1): -8.0
Math.ceil(-8.9): -8.0
容易混淆的某些Math方法说明的更多相关文章
- javascript 取整,取余数 math方法
1.丢弃小数部分,保留整数部分 parseInt() 函数可解析一个字符串,并返回一个整数. parseInt(string, radix) 参数 描述 string 必需.要被解析的字符串. rad ...
- 较常用的Math方法及ES6中的扩展
记录下与Math有关的常用方法,如:求最大值.最小值等,或者是保留几位数啥的 1.数据 let floatA = 2.325232; let floatB = 2.3456; let temporar ...
- JavaScript 数学 (Math) 方法
一.Math 方法 1.Math.round(x) 的返回值是 x 四舍五入为最接近的整数: Math.round(7.8); // 返回 8 Math.round(3.3); // 返回 3 2.M ...
- 常用Math 方法
/** * * @authors Your Name (you@example.org) * @date 2016-11-18 11:26:44 * @version $Id$ */ Math.pow ...
- js中Number对象与MATH方法整理总结
W3C的文档: Number 对象属性 属性 描述 constructor 返回对创建此对象的 Number 函数的引用. MAX_VALUE 可表示的最大的数. MIN_VALUE 可表示的最小的数 ...
- math方法
1.丢弃小数部分,保留整数部分parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3,四舍五入. Math.round(5/2) 4,向下取整 Math.fl ...
- js中常用的Math方法总结
1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); ...
- JS中常用的Math方法
1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); ...
- 转:C#使用Dotfuscator混淆代码的加密方法
Author:flymorn Source:flymornCategories:C#编程 PostTime:2011-9-16 1:04:49 正 文: C#编写的代码如果不进行一定程度的混淆和加 ...
随机推荐
- shell的条件判断
.字符串判断 str1 = str2 当两个串有相同内容.长度时为真 str1 != str2 当串str1和str2不等时为真 -n str1 当串的长度大于0时为真(串非空) -z str1 当串 ...
- thinkcmf5 iis+php重写配置
TP在本机运行非常好,谁想到服务器上后,连http://www.***.com/wap/login/index都404错误了, 中间的郁闷过程不表. 解决方案分两步: 第一步: 下载rewrite_2 ...
- 添加SQL字段
通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数增加字段: alter table [表名] add 字段名 smallin ...
- NAND Flash和NOR Flash的比较
目前Flash主要有两种NOR Flash和NADN Flash.NOR Flash的读取和我们常见的SDRAM的读取是一样,用户可以直接运行装载在NOR FLASH里面的代码,这样可以减少SRAM的 ...
- POJ1426-Find The Multiple(搜索)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42035 Accepted: 176 ...
- HDU:1358-Period
Period Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Desc ...
- 用 Tensorflow 建立 CNN
稍稍乱入的CNN,本文依然是学习周莫烦视频的笔记. 还有 google 在 udacity 上的 CNN 教程. CNN(Convolutional Neural Networks) 卷积神经网络简单 ...
- Android开发——常见的内存泄漏以及解决方案(一)
0. 前言 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52333954 Android的内存泄漏是Android开发领域永恒的 ...
- MySQL基础6-分组查询
1.分组函数 需求20:查询所有商品平均零售价SELECT AVG(salePrice) FROM product 需求21:查询商品总记录数SELECT COUNT(id) count FROM p ...
- 【Best Time to Buy and Sell Stock】cpp
题目: Say you have an array for which the ith element is the price of a given stock on day i. If you w ...