NSNumberFormatter stringFromNumber returns incorrectly rounded value
Originator: | daikini | ||
Number: | rdar://18468186 | Date Originated: | 2014-09-26 |
Status: | Open | Resolved: | |
Product: | iOS, OS X | Product Version: | iOS 8, OS X 10.10 |
Classification: | Serious Bug | Reproducible: | Always |
Summary: NSNumberFormatter stringFromNumber returns an incorrectly rounded value on iOS 8 and OS X 10.10. Previous iOS and OS X releases returned the correct value. The issue seems to be related to the usesSignificantDigits and maximumSignificantDigits set on the formatter. According to the API documentation[1] maximumSignificantDigits will only be used when usesSignificantDigits is set to YES. It appears that maximumSignificantDigits is being used regardless of the usesSignificantDigits value. [1] https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumberFormatter_Class/index.html#//apple_ref/occ/instp/NSNumberFormatter/usesSignificantDigits Steps to Reproduce: 1. Create an NSNumberFormatter NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; 2. Set the properties on the formatter [formatter setUsesSignificantDigits:NO]; [formatter setMaximumSignificantDigits:2]; 3. Create a number to format NSNumber *number = @(291.99); 4. Format the number NSString *formattedNumber = [formatter stringFromNumber:number]; Expected Results: formattedNumber should contain @"292". Actual Results: formattedNumber contains @"290". Version: iOS 8 [12A365], OS X 10.10 [14A361c] Configuration: Not device specific.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!