Math.PI // 3.141592653589793
// 弧度转角度
Math.toDegrees(Math.PI);// 180.0
// 角度转弧度
Math.toRadians(180);// 3.141592653589793
Math.sin(Math.toRadians(90));// 1.0
Math.cos(Math.toRadians(180));// -1.0
Math.tan(Math.toRadians(45));// 0.9999999999999999
// 向下取整
Math.floor(32.356);// 32.0
// 向上取整
Math.ceil(32.356);// 31.0
// 四舍五入(保留整数)
Math.round(32.356);// 32
// 四舍五入(自定义小数位数)
String sData = new DecimalFormat("#.##").format(32.356);
System.out.println(sData); // 32.36
注:#.##和0.00的区别:
00是几个0就一定有这么多位小数,不够使用0补全;
##如果最后是0则省略。
System.out.println(new DecimalFormat("#.##").format(21.2));// 21.2
System.out.println(new DecimalFormat("0.00").format(21.2));// 21.20
// 平方根
Math.sqrt(2);// 1.4142135623730951
// 最小值
Math.min(2, 5);// 2
// 最大值
Math.max(2, 5);// 5