iPhone,如何删除本地化的货币格式并生成双倍?(iPhone, how do I remove the localized currency format and produce a double?)
我已经找到了关于如何使用用户当前货币设置本地化字符串的优秀问题/答案... localize-currency-for-iphone
这是使用的代码......
NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithString:@"5.00"]; NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init]; [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; NSLog(@"%@", [currencyFormatter stringFromNumber:someAmount]);但是,我需要将其转换为double,以便将其存储到我的数据库中?
编辑:那应该读取我需要将其转换回字符串而不进行货币格式化,然后将其转换为双精度。
I've 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.
最满意答案
取字符串并调用反向方法:
NSNumber* number = [currencyFormatter numberFromString:string];Take the string and call the reverse method:
NSNumber* number = [currencyFormatter numberFromString:string];更多推荐
发布评论