The decimal number "22.4" cannot be represented exactly by a binary floating point number such as float
or double
. So "rounding a float to 22.4" does not make sense, because there is no float that is exactly equal to 22.4.
You can only specify a precision if you convert the floating point number to a decimal string for output. You can use a NSNumberFormatter
or a printf-format like "%.<precision>f
.