Please see the pictures:
I'm amazing the result is different.
A CGFloat
is actually a double
on 64 bit platforms. (It was a float
on old 32 bit platforms.)
So here you're dividing a double
by a double
:
CGFloat price = 88888736 / a;
^^^^^ ^^^^^^^^ ^
double int -> double double
and here you're dividing a double
by a float
:
CGFloat price2 = 88888736 / 100.0f;
^^^^^^ ^^^^^^^^ ^^^^^^
double int -> double float
Change 100.0f
to either 100.0
or (CGFloat)100
and you should be fine.
CGFloat
is a double
on your machine, therefore what you are doing is this:
double a = 100.00f
double price = 88888736 / a
float a2 = 100.00f // `float` type enforced by the trailing `f`
double price2 = 88888736 / a2
The difference is that in the first case the division is a double
division while in the second case this is a float
division where the result is then assigned to a double
. Since float
division has less precision, you get the result you are seeing.