Math.round()方法
来源:互联网 发布:python spark sql 编辑:程序博客网 时间:2024/05/18 00:42
Math.round()即四舍五入,看如下代码:
public class MathTest { public static void main(String[] args) { System.out.println("小数点后第一位=5"); System.out.println("正数:Math.round(11.5)=" + Math.round(11.5)); System.out.println("负数:Math.round(-11.5)=" + Math.round(-11.5)); System.out.println(); System.out.println("小数点后第一位<5"); System.out.println("正数:Math.round(11.46)=" + Math.round(11.46)); System.out.println("负数:Math.round(-11.46)=" + Math.round(-11.46)); System.out.println(); System.out.println("小数点后第一位>5"); System.out.println("正数:Math.round(11.68)=" + Math.round(11.68)); System.out.println("负数:Math.round(-11.68)=" + Math.round(-11.68)); }}
输出结果为:
小数点后第一位=5
正数:Math.round(11.5)=12
负数:Math.round(-11.5)=-11
小数点后第一位<5
正数:Math.round(11.46)=11
负数:Math.round(-11.46)=-11
小数点后第一位>5
正数:Math.round(11.68)=12
负数:Math.round(-11.68)=-12
结论:
1、参数的小数点后第一位<5,运算结果为参数整数部分。
2、参数的小数点后第一位>5,运算结果为参数整数部分绝对值+1,符号(即正负)不变。
3、参数的 小数点后第一位=5,正数运算结果为整数部分+1,负数运算结果为整数部分。
总结: 大于五全部加,等于五正数加, 小于五全不加。
0 0
- Math.Round 方法
- Java Math.round方法
- Math.round()方法
- Math.round()方法
- Math.round()方法
- Math.round与Math.floor方法
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- .net Math.Round方法详解
- Math ceil()、floor()、round()方法
- Android中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
- Java中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
- Math中的round/ceil/floorf方法总结
- Math.Round()方法的四舍五入(.NET)
- Math ceil(),floor(),round()方法的使用
- Math中的round/ceil/floorf方法总结
- 关于java Math.round(Double a) 方法
- Word2016中如何设置前几页不要页眉?文档快速‘另起一页’(毕业论文中常见问题)
- 关于Scroller的一点问题
- Ecshop模板开发(二十九):商品列表、排序、分页显示
- 深度学习小白——tensorflow(四)CIFAR-10实例
- c++父类和子类构造函数和析构函数执行顺序
- Math.round()方法
- 蓝桥杯 报时助手
- Python 代码调试技巧使用 PyDev 进行调试
- chimerge数据离散化算法
- Console 控制台 字符串输入的格式问题
- JAVA初识
- 重构工具安装 Jalopy,CheckStyle,FindBugs,JDeodorant,Stench Blossom
- 单例设计模式的应用场景
- 统计学习方法(1)——正则化、误差上界的证明等