小数を保持する Java 除算

DecimalFormat decimalFormat = new DecimalFormat("#.####");
int total = patrolList.size();
Integer value = entry.getValue();
BigDecimal bigDecimalTotal = new BigDecimal(total);
BigDecimal bigDecimalExc = new BigDecimal(value);
BigDecimal rate = bigDecimalExc.divide(bigDecimalTotal, 4, BigDecimal.ROUND_HALF_UP);
String format1 = decimalFormat.format(rate.multiply(new BigDecimal(100)));

上記は小数点以下 4 桁の例です。

おすすめ

転載: blog.csdn.net/qq_45443475/article/details/131492574