Java language learning tools with mathematical summary of the relevant articles of the Advanced Math absolute value rounded up rounded down

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:
result

Published 50 original articles · won praise 3 · Views 5176

Guess you like

Origin blog.csdn.net/Ace_bb/article/details/104073226