后端修行 - 常用小功能

持续记录

临时数据

String tempData = "5.20"

向上取整(Math.ceil())

Math.ceil(Double.parseDouble(tempData))

输出值:6.0

向下取整(Math.floor())

Math.floor(Double.parseDouble(tempData))

输出值:5.0

四舍五入(Math.round())

long round = Math.round(tempData);

输出值:5.0

绝对值获取(Math.abs())

主要作用 :负数变正数

public static void main(String args[]) {
	    //这里是负数
		System.out.println (Math.abs (-6.6));          
		System.out.println (Math.abs (4.8));   
	}

输出值:
6.6
4.8

发布了247 篇原创文章 · 获赞 97 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/qq_20451879/article/details/100098009