本文共 1393 字,大约阅读时间需要 4 分钟。
Java有四舍五入函数--Math.round,通过一个例子看看他的用法:
- package math;
-
- public class MathRoundTest {
-
-
-
-
-
-
-
-
-
- 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));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- }
转载地址:http://itxgi.baihongyu.com/