Loading

5_Math数学工具类的使用

Math 数学工具类的使用

1. abs(num) : 获取绝对值

// 获取绝对值
System.out.println(Math.abs(3.14));  // 3.14
System.out.println(Math.abs(-2.4));  // 2.4

2. ceil(num) : 向上取整

// 向上取整
System.out.println(Math.ceil(2.1));  // 3.0

3. floor(num) : 向下取整

// 向下取整
System.out.println(Math.floor(2.9));  // 2.0

4. 四舍五入

// round(num) : 四舍五入
System.out.println(Math.round(2.4)); // 2
System.out.println(Math.round(2.5));  // 3
System.out.println(Math.round(2.6));  // 3

5. Math.PI : 近似圆周率常量 (double)

System.out.println(Math.PI);  // 3.141592653589793
posted @ 2019-12-01 12:01  未来已来,你来不来  阅读(136)  评论(0编辑  收藏  举报