我想要为ex:
舍入一个值12.166666 ----> 12.00
12.49999 ----> 12.00
12.5111 ----> 13.00
12.9999 ----> 13.00
我想要以50比例结束。
答案 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)