日期:2014-05-20  浏览次数:20981 次

double 值 取前四位,怎么取(四舍五入)?
如   double   d=0.00751953125;
取前四位后d=0.0075

------解决方案--------------------
public static double round(double d, int n) {
d = d * Math.pow(10, n);
d = Math.round(d);
return d / Math.pow(10, n);
}
------解决方案--------------------
Double d = 0.00751953125;
DecimalFormat df = new DecimalFormat( "###,###.0000 ");
System.out.println(df.format(d));


------解决方案--------------------
public Double Round(Double d,int scale){
BigDecimal big = new BigDecimal(d);
return big.setScale(scale,BigDecimal.ROUND_HALF_UP).doubleValue();
}