Use setRoundingMode, set the RoundingMode explicitly to handle your issue with the half-even round, then use the format pattern for your required output. Example: DecimalFormat df = new DecimalFormat("#.####");...
Double decimal formatting in Java
I have these two variables double num = 540.512 double sum = 1978.8 Then I did this expression double total = Math.round((num/ sum * 100) * 10) / 10;...