Java division preserving decimals

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

The above is an example with four decimal places.

Guess you like

Origin blog.csdn.net/qq_45443475/article/details/131492574