public static void main(String args[]) {
for (int i = 0; i < 10; i++) {
//方法一
int i1 = (int)((Math.random()*10+1)*100);
double d=(double)i1/100;
sop("method_1:"+d);
//方法二
double i2=Math.random()*10+1;
DecimalFormat dcf=new DecimalFormat("###.0000");
sop("method_2::::"+dcf.format(i2));
}
}
Java_保留小数点的后两位
最新推荐文章于 2022-10-24 16:20:58 发布