Why is result NSOrderedDescending?
NSDecimalNumber *decimal = [[NSDecimalNumber alloc] initWithString:@"2.6"];
NSComparisonResult result = [decimal compare:[NSNumber numberWithFloat:2.6]];
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
2.6cannot be represented exactly as a floating-point number, butNSDecimalcan represent this value exactly (that’s why we need NSDecimals in the first place).According to IEEE 754 Calculator,
2.6gets converted to2.5999999046325684, which is less than2.6, and therefore compares asNSOrderedDescending.