I know two versions of the answer to your question. One is, do you have a “principles of computing” module; that should explain how IEEE754 numbers work. There is an article on
Wikipedia, but I found that incomprehensible. The only thing that enabled me to know anything about IEEE754 numbers was a half‑hour's explanation in a lecture. That includes the bit about how a
double uses 52 bits' space to get 53 bits' precision. But that still isn't enough for all applications. If I look at my internet banking and find there is a difference between my “balance“ and “available balance”, I can go into JShell and subtract the figures and get a result like 18.48999999999997. Then I can remember that I put £18.49 on the card at shop XXX yesterday.
If you need to specify the kind of rounding, or you need precision, don't use
float or
double arithmetic: use decimal arithmetic with one of the following classes:-
BigInteger (integers only) BigDecimal (decimal fractions). Never use floating‑point arithmetic for money.