容易混淆的某些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#编写的代码如果不进行一定程度的混淆和加 ...
随机推荐
- js数据结构与算法--递归
递归,函数自己调用自己 return 返回值, 后面的代码不执行 function fn(num){ console.log(num) if(num == 0){ return; } fn(num-1 ...
- 【CodeBase】通过层级键在多维数组中获取目标值
通过层级键在多维数组中获取目标值 /* *Author : @YunGaZeon *Date : 2017.08.09 *param data : Data Array *param keys : K ...
- JZOJ 5347. 遥远的金字塔
Description Input Output Sample Input 5 3 1 6 1 5 3 5 4 4 4 4 Sample Output 15 Data Constraint 做法: 其 ...
- Hie with the Pie POJ - 3311
Hie with the Pie POJ - 3311 The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...
- BFS:HDU2612-Find a way(双向BFS)
Find a way Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- (ADO.NET)SqlCommand参数化查询
string strcon = "Persist Security Info=False;User id=sa;pwd=lovemary;database=student;server=(l ...
- vue时时监听input输入框中 输入内容 写法
Vue input 监听 使用 v-on:input="change" 实现即可 App.vue <template> <div> <md-field ...
- Codeforces 653G Move by Prime 组合数学
题意: 有一个长度为\(n\)的正整数序列\(a\),有这样一种操作: 每次可以选序列中的某一个数乘上或除以某一个素数. 求对于每一个子序列使其所有元素相等的最少操作次数之和. 分析: 因为两个素数之 ...
- 纯javascript验证,100行超精简代码。
这篇文章转自--寒飞,原帖地址http://blog.csdn.net/luoyehanfei/article/details/42262249 QQ交流群235032949 纯javascript验 ...
- kickstart配置文件详解和system-config-kickstart
kickstart是什么 许多系统管理员宁愿使用自动化的安装方法来安装红帽企业 Linux.为了满足这种需要,红帽创建了kickstart安装方法.使用kickstart,系统管理员可 ...