07-21-2023, 10:13 PM
It is not a matter of how the number is stored, it is a matter of how you are displaying it. When converting it to a string you must round to the desired precision, which in your case is two decimal places.
E.g.:
NSString* formattedNumber = [NSString stringWithFormat:@"%.02f", myFloat];
`%.02f` tells the formatter that you will be formatting a float (`%f`) and, that should be rounded to two places, and should be padded with `0`s.
E.g.:
%f = 25.000000
%.f = 25
%.02f = 25.00
E.g.:
NSString* formattedNumber = [NSString stringWithFormat:@"%.02f", myFloat];
`%.02f` tells the formatter that you will be formatting a float (`%f`) and, that should be rounded to two places, and should be padded with `0`s.
E.g.:
%f = 25.000000
%.f = 25
%.02f = 25.00