1 public static String divToString(double v1, double v2, int scale){ 2 if (scale < 0) { 3 throw new IllegalArgumentException( 4 "The scale must be a positive integer or zero"); 5 } 6 BigDecimal b1 = new BigDecimal(Double.toString(v1)); 7 BigDecimal b2 = new BigDecimal(Double.toString(v2)); 8 return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).toString(); 9 }
只要将BigDecimal 对象toString()就好。