NSNumberFormatter wrongly parses decimal numbers as strings

Originator:thom.union
Number:rdar://11234941 Date Originated:2012-04-12
Status:Open Resolved:No
Product:iPhone SDK Product Version:5.0.0
Classification:Bug Reproducible:Yes
 
Summary:
I'm trying to convert NSString value "8.11" with NSNumberFormatter with generatesDecimalNumbers=YES. After calling getObjectValue on formatter returned value should have decimal number with value "8.11", but it's decimal with value "8.10999999999". This means that internally number is parsed as float or someting similiar instead of decimals. [NSDecimalNumber decimalNumberFromString:@"8.11"] returns correct values, so it's only NSNumberFormatter bug.

Steps to Reproduce:

NSNumberFormatter *nformatter = [[NSNumberFormatter alloc] init];
[nformatter setNumberStyle:NSNumberFormatterDecimalStyle];
[nformatter setGeneratesDecimalNumbers:YES];
[nformatter setMaximumFractionDigits:2];
[nformatter setMinimumFractionDigits:2];

NSDecimalNumber *value;
[nformatter getObjectValue:&value forString:@"8.11" errorDescription:nil];
NSLog(@"value=%@",value);

Expected Results:

value should be equal to "8.11".

Actual Results:

value is equal to "8.10999999999".

Regression:

Notes:

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!