开发者

iPhone, how do I remove the localized currency format and produce a double?

开发者 https://www.devze.com 2023-01-21 16:52 出处:网络
I\'v开发者_Go百科e found this excellent question / answer on how localize a string with the users current currency settings... localize-currency-for-iphone

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消