四舍五入 round 默认为long
Math.round(float) 返回的是int,
Math.round(double) 返回值是 long。
96.1 默认是double,加上 “F”,
正确是是 int round = Math.round(96.1F);
long round = Math.round(96.1);
int round1 = Math.round(96.1F);
Math.ceil(96.1));// 97 (去掉小数凑整:不管小数是多少,都进一)向上取整
(int) Math.floor(96.8));// 96 (去掉小数凑整:不论小数是多少,都不进位) 向下取整
Math.round(96.8));// 97 四舍五入取整
floor,ceil 默认是 double
double floor = Math.floor(weightCount / 2.0);
double ceil = Math.ceil(weightCount / 2.0);
float double int区别,小数默认为double
float a1 = (float) 2.17654765;
System.out.println(a1); // 2.1765478
double a2 = 3.734765323445;
System.out.println(a2); //3.73476532344
int a3 = (int) a2;
System.out.println(a3); // 3
//四舍五入
long round = Math.round(a2);
System.out.println(round); // 4
int a4 = (int) Math.round(a2);
System.out.println(a4); // 4
//向0取整
double floor = Math.floor(a2);
System.out.println(floor); // 3.0
int a5 = (int) Math.floor(a2);
System.out.println(a5); //3