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();
}