@Test
public void test1() {
System.out.println(Math.round(3.015*100));
System.out.println(Math.round(301.5));
System.out.println(Math.round(4.015*100));
System.out.println(Math.round(401.5));
System.out.println(Math.round(301.5)/100);
System.out.println(Math.round(3.5));
System.out.println(Math.round(3.015*100)/100.0);
System.out.println(round(3.015));
System.out.println(Math.round(4.015*100)/100.0);
System.out.println(round(4.015));
}
public double round(double value){
return Math.round(value*100)/100.0;
}
public void test1() {
System.out.println(Math.round(3.015*100));
System.out.println(Math.round(301.5));
System.out.println(Math.round(4.015*100));
System.out.println(Math.round(401.5));
System.out.println(Math.round(301.5)/100);
System.out.println(Math.round(3.5));
System.out.println(Math.round(3.015*100)/100.0);
System.out.println(round(3.015));
System.out.println(Math.round(4.015*100)/100.0);
System.out.println(round(4.015));
}
public double round(double value){
return Math.round(value*100)/100.0;
}
解决方案 »
- 关于批量数据插入Mysql数据库中,并返
- 可移动的浮动框的实现方法?
- 各位大侠帮帮忙!我是新手!急
- codelogic
- 服务器系统时间的问题
- java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
- java人才急求
- Java 语言基本上属于一个完全面向对象的语言,Java相关的重要术语解析
- 在做spring跳转时,发现跳转后的IE地址栏内的URL还是请求时候的URL,有什么办法强制改变过来吗?
- 关于Eclipse3.1插件问题,请教:)
- xfire+spring2.0 创建一个WEBSERVICE服务
- 记不得这是项目中遇到的第几个问题了
302
401
402
3
4
3.02
3.02
4.01
4.01
System.out.println(Math.round(401.5));感觉和运算方式有关,4.015*100可能是double类型,401.5按照float类型计算。个人感觉,说得不对别拍砖。其他的没发现什么问题。
System.out.println((4.015 * 100));
输出
401.49999999999994
System.out.println(Math.round(4.015f * 100));
double abc = 4.015; //4.025
abc = new java.math.BigDecimal(Double.toString(abc)).setScale(2,java.math.BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println(abc*100);