在JAVA中完成

时间:2012-08-30 06:10:48

标签: java

我想要为ex:

舍入一个值
  

12.166666 ----> 12.00

     

12.49999 ----> 12.00

     

12.5111 ----> 13.00

     

12.9999 ----> 13.00

我想要以50比例结束。

2 个答案:

答案 0 :(得分:9)

您可以查看Math.round(double a)方法。

System.out.println(Math.round(12.51));//Yields 13
System.out.println(Math.round(12.49));//Yields 12
System.out.println(Math.round(12.50));//Yields 13

答案 1 :(得分:0)

您可以使用Math.round。有关文档,请查看: http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round(double)