Mathematics Math Tools
Math.abs () takes the absolute value
Math.ceil () rounded up
Math.floor () rounded down
Math.round () rounding
directly look at the code:
public class MathTool {
public static void main(String[] args) {
//获取绝对值
System.out.println(Math.abs(-3.14));
System.out.println(Math.abs(-0.5555555555555));
System.out.println("======================");
//向上取整
System.out.println(Math.ceil(3.9));
System.out.println(Math.ceil(3.1));
System.out.println("======================");
//向下取整
System.out.println(Math.floor(321.9));
System.out.println(Math.floor(321.1));
System.out.println("======================");
//四舍五入
System.out.println(Math.round(3.44444));
System.out.println(Math.round(3.5555555555));
}
}
Output: