【Java笔记】java数学工具类Math

java数学工具类Math

Math工具类提供大量静态方法,完成与数学运算相关操作

abs()

获取绝对值

System.out.println( Math.abs.(-8.57) );  //8.57

ceil()

向上取整

System.out.println( Math.ceil(7.2) );  //8.0

floor()

向下取整抹零

System.out.println( Math.floor(23.2) );  //23.0

round()

四舍五入

System.out.println( Math.round(34.3) );  //34
System.out.println( Math.round(34.5) );  //35

Math.PI

近似的圆周率常量

System.out.println( Math.PI );  //3.141592653589793
posted @ 2021-06-02 17:42  半袋咖啡  阅读(96)  评论(0编辑  收藏  举报