Java float保留2位或多位小数

float f = 0.123456f;
float f2 = (float)(Math.round(f*100))/100;
System.out.println(f2);

//结果:0.12

猜你喜欢

转载自www.cnblogs.com/dch0/p/12580892.html