如何使用Math.round () :
将两个int类型的数相除后,将保留两位小数。
int a=1188;
int b=93;
double c;
c=(double ) ) math.round ) a*100/b )/100.0 ); //这样可以保持两位数
打印结果: c=0.12
c=newdouble(math.round ) a*1000/b )/1000.0 ); //这样可以保持3位
打印结果: c=0.012
2 .另一种方法
import java.text.DecimalFormat;
decimal format df2=new decimal format (# #.00 ); //这样可以保持两位数
decimal format df2=new decimal format (# #.000 ); //这样可以保持3位
system.out.println(df2.format )双精度类型变量);
PS:
Math.round ()的作用:
double a=123.55
system.out.println (math.round (a ) );
打印结果: 124