Why is result
NSOrderedDescending
?
NSDecimalNumber *decimal = [[NSDecimalNumber alloc] initWithString:@"2.6"];
NSComparisonResult result = [decimal compare:[NSNumber numberWithFloat:2.6]];
Why is result
NSOrderedDescending
?
NSDecimalNumber *decimal = [[NSDecimalNumber alloc] initWithString:@"2.6"];
NSComparisonResult result = [decimal compare:[NSNumber numberWithFloat:2.6]];
2.6
cannot be represented exactly as a floating-point number, but NSDecimal
can represent this value exactly (that's why we need NSDecimals in the first place).
According to IEEE 754 Calculator, 2.6
gets converted to 2.5999999046325684
, which is less than 2.6
, and therefore compares as NSOrderedDescending
.