保留两位小数
方案一
Double totalSaleAmount = 4.174558045899999E7; DecimalFormat df = new DecimalFormat("#.##"); System.out.println("df.format(totalSaleAmount) = " + df.format(totalSaleAmount));
方案二
Double totalSaleAmount = 4.174558045899999E7; NumberFormat percentInstance = NumberFormat.getPercentInstance(); percentInstance.setMinimumFractionDigits(2); Double a = percentInstance.format(totalSaleamount); System.out.println(a);
结果图
标签:Java,format,df,Double,乱码,percentInstance,totalSaleAmount,小数 From: https://www.cnblogs.com/saoge/p/17495411.html