iPhone,如何删除本地化的货币格式并生成双倍?(iPhone, how do I remove the localized currency format and produce a double

编程入门 行业动态 更新时间:2024-10-26 15:21:21
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];

更多推荐

本文发布于:2023-07-30 06:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336745.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双倍   货币   格式   remove   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!