常用方法
- public static final double PI:
- public static final double E:
- public static int abs(int a): 取绝对值
- public static double ceil(double a) 向上取整
- public static double floor(double a) 向下取整
- public static int round(float a) 四舍五入
- public static double pow(double a, double b) a的b次方
- public static double max(double a, double b) 两个数的最大值
- static double rint(double a) 返回最接近a的整数值,如果有两个同样接近的整数,则结果取偶数
例:- Math.rint(1.5);
- Math.rint(2.5);
- static int round(float a) "4舍5入" 加0.5向下取整
代码
public static void main(String[] args) {
System.out.println("Math.round(1.4) = " + Math.round(1.4));
System.out.println("Math.round(1.5) = " + Math.round(1.5));
System.out.println("Math.round(-1.4) = " + Math.round(-1.4));
System.out.println("Math.round(-1.5) = " + Math.round(-1.5));
}