NSLog(@"original float value = %f", [anNSNumber floatValue]);
float newFloat = [anNSNumber floatValue] - 1.0f;
NSLog(@"newFloat = %f", newFloat);
Gives me
orginal float value = 215987480044765184.000000
newFloat = 215987480044765184.000000
How do you simply subtract 1 from a float?
No, you cannot simplify it further. Floating point number is different from integer.
Another thing to note is that
floattype can only contain up to 24 bit of precision (around 6-7 decimal digits of precision). The number you have there exceeds the precision available forfloat, and the subtraction amount is too small to affect in the 24 bit of precision, so the operation simply does not make any change to the result.The problem is not fixed even if you do the operation in
double, since the number even exceeds the 53 bit precision fordouble.Depends on your requirement, a 64-bit integer type (
long longtype, or more specificint64_t) may be what you need. If such precision is necessary for even bigger number, basic type won’t be sufficient. External library may be needed if you need very high precision.