//测试double保留两位小数方法一
double d1= 1.5678;
d1=(Math.round(d1*100));
d1/=100;
System.out.println(d1);
//==方法二
BigDecimal bd = new BigDecimal(1.235543);
bd = bd.setScale(2,BigDecimal.ROUND_HALF_EVEN);
double d = bd.doubleValue();
System.out.println(d);
//==方法三
double x = 1.3355;
java.text.NumberFormat formate = java.text.NumberFormat.getNumberInstance();
formate.setMaximumFractionDigits(2);//设定小数最大为数 ,那么显示的最后会四舍五入的
String m = formate.format(x);
System.out.println(m);
//==方法四
DecimalFormat decfmt = new DecimalFormat("0.00");
System.out.println(decfmt.format(2.33782222));
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。