If you read http://en.wikipedia.org/wiki/Floating_point ... you will find that any number greater than about 10,000 should use 64 bit float instead of 32 bit float if you want to have four decimal places .
The data type doubleis a 64-bit float.
Be especially careful with CGFloat, because it will be 64 bits on the iPhone 5S and 32 bits on the iPhone 5C and any previous iPhone.
64-bit float is accurate for billions of numbers. Anything more and you will want to get started with the class NSDecimalNumber. This is probably what you should do for the calculator application.
https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/classes/nsdecimalnumber_class/reference/reference.html
, float double, :
float aFloat = 10000.2;
float bFloat = 10000.0;
NSLog(@"%.15f", aFloat - bFloat);
double aDouble = 10000.2;
double bDouble = 10000.0;
NSLog(@"%.15f", aDouble - bDouble);
NSDecimalNumber *a = [NSDecimalNumber decimalNumberWithString:@"10000.2"];
NSDecimalNumber *b = [NSDecimalNumber decimalNumberWithString:@"10000.0"];
NSLog(@"%@", [a decimalNumberBySubtracting:b]);
:
float aFloat = 10000000000000000000000.2;
float bFloat = 10000000000000000000000.0;
NSLog(@"%.15f", aFloat - bFloat);
double aDouble = 10000000000000000000000.2;
double bDouble = 10000000000000000000000.0;
NSLog(@"%.15f", aDouble - bDouble);
NSDecimalNumber *a = [NSDecimalNumber decimalNumberWithString:@"10000000000000000000000.2"];
NSDecimalNumber *b = [NSDecimalNumber decimalNumberWithString:@"10000000000000000000000.0"];
NSLog(@"%@", [a decimalNumberBySubtracting:b]);