标签:port 2.7 math类 ring math ceil floor time class
数字的格式化
①Math类:
abs(); 绝对值
public class Test {
public static void main(String[] args) {
int a = Math.abs(-7);
System.out.println(a); // 打印7
}
ceil(); 向上取整
floor(); 向下取整
public class Test {
public static void main(String[] args) {
double d1 = Math.ceil(12.345);
double d2 = Math.ceil(12.745);
double d3 = Math.floor(12.345);
double d4 = Math.floor(12.745);
System.out.println(d1); //打印13
System.out.println(d2); //打印13
System.out.println(d3); //打印12
System.out.println(d4); //打印12
}
}
round(); 四舍五入取整
public class Test {
public static void main(String[] args) {
double d5 = Math.round(13.111);
double d6 = Math.round(13.711);
System.out.println(d5); //打印13
System.out.println(d6); //打印14
}
}
random(); 取随机数(0-1,不包括1)
还可以用java.util.Random
nextInt(int bounds)
全球唯一标识 UUID 一般用于文件上传,重名的。上传时随机生成改名
import java.util.UUID;
public class Test {
public static void main(String[] args) {
UUID uuid = UUID.randomUUID();
System.out.println(uuid); //打印一个很长的名字
}
}
Date 时间戳 某一个时间点到当前时间的毫秒数,弊端:服务器快会重名
public class Test {
public static void main(String[] args) {
Date date = new Date();
System.out.println(date.getTime()); //一串数字
}
}
标签:port 2.7 math类 ring math ceil floor time class
原文地址:https://www.cnblogs.com/syx1997/p/9008369.html