BigDecimal 结果保存百分比

public static void main(String[] args) {
    BigDecimal a = new BigDecimal(10);
    BigDecimal b = new BigDecimal(3);
    BigDecimal divide = a.divide(b, 2, BigDecimal.ROUND_HALF_UP);
    System.out.println(divide);
    NumberFormat numberFormat = NumberFormat.getPercentInstance();
    numberFormat.setMaximumFractionDigits(2);
    divide.doubleValue();
    System.out.println(numberFormat.format(divide.doubleValue()));
}

你可能感兴趣的:(Java)