There are two things to observe with floating point values:
- They can not represent most values exactly
- Printed values are rounded to a specified or default resolution which might be affected by the above
79999.95 is one of the values where the first point applies. It can't be represented exactly with a
double
. The stored value is 79999,949999999997 which can be verified by setting a corresponding output precision (17 significant digits). For a single precision
float
, the stored value would be 79999,95313.
The limited resolution and inaccuracy is not a problem for simple mathematic operations. But it might become a problem with complex operations where rounding errors can accumulate. Then the algorithm implementation has to take care of that.
The problem of showing a probably wrong rounded value is no problem when knowing about the precision of the value itself. And you should know that for your input values.
Related reads:
The Floating-Point Guide[
^]
What Every Computer Scientist Should Know About Floating-Point Arithmetic[
^]