The value 22.8 can not be represented in binary floating point exactly. What you are seeing is a representation based on the display format. Different display methods may use different display formats. Displaying different number of digits and the rounding means that both 22.8 and 22.7999999 are correct for the number of digits displayed after rounding. Note that 22.7999999 was displayed and not 22.8000000 because the next digit was 2 so the value displayed was rounded down.
This is base dependent, that is things that can be exact in one number base may not be able to be exact in a different number base. In this case 22.8 in the decimal number base can not be exact in the binary number base.
This is the reason that NSDecimal exists and the reason floating point is not used for monetary values.
This is somewhat equivalent to displaying the value of pi in base decimal, the number of digits is infinite so for every display someone decided how many digits to show. Interestingly, pi can be represented exactly (but usefully) in the pi number base. :-)
In the case of float
and double
there is a finite number of digits that can be represented.