iPhone, how do I remove the localized currency format and produce a double?
I'v开发者_Go百科e found this excellent question / answer on how localize a string with the users current currency settings... localize-currency-for-iphone
This is the code used...
NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithString:@"5.00"];
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSLog(@"%@", [currencyFormatter stringFromNumber:someAmount]);
However, I need to convert this to a double so I can store it to my database?
EDIT: That should read I need to convert this back to a string without the currency formating, then convert it to a double.
Take the string and call the reverse method:
NSNumber* number = [currencyFormatter numberFromString:string];
精彩评论