In 5.0, it is simply shown that the exact result, as Java understands, is closer to 5.0 than to any other double. This does not mean that the exact result of the operation is exactly 5.
Now, when you request a module, you can go to a much finer level of detail, because the result is not tied to part "5".
This is not a great explanation, but imagine that you have a decimal floating point type with 4 digits of precision. What is the result of 1000 / 99.99 and 1000% 99.99?
Well, the real result starts at 10.001001 - so you need to round it to 10.00. However, the remainder is 0.10, which you can express. So, again, it seems like splitting gives you an integer, but that is not entirely true.
With that in mind, keep in mind that your literal 5.6 is actually 5.599999999999999996447286321199499070644378662109375. Now itโs clear that 28.0 (which * can be) is represented exactly divided by this number, not exactly 5.
EDIT: now, if you are doing the result with decimal floating point arithmetic using BigDecimal , the value is really 5.6, and there is no problem:
import java.math.BigDecimal; public class Test { public static void main(String[] args) { BigDecimal x = new BigDecimal("28.0"); BigDecimal y = new BigDecimal("5.6"); BigDecimal div = x.divide(y); BigDecimal rem = x.remainder(y); System.out.println(div);
source share