不要从numbernormatter获取货币符号

发布于 2025-02-10 09:46:15 字数 241 浏览 1 评论 0原文

以下代码的输出为: ars 59.00 。为什么没有打印符号?

let formatter = NumberFormatter()
formatter.currencyCode = "ARS"
formatter.numberStyle = .currency
print(formatter.string(from: NSNumber(value: 59.00)) ?? "na")

The output of following Code is: ARS 59.00. Why is there no symbol printed?

let formatter = NumberFormatter()
formatter.currencyCode = "ARS"
formatter.numberStyle = .currency
print(formatter.string(from: NSNumber(value: 59.00)) ?? "na")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请别遗忘我 2025-02-17 09:46:15

强迫自定义语言环境

显示货币,您需要为当前语言环境显示货币符号($,€,¥,£)。

NumberFormatter将显示正确的符号,并且您可能没有意识到的格式与您的使用符号有很大不同。 审视

  • 分组分隔机 -在美国
  • 进行
  • 不同的国家使用不同的小数分隔符和 //supereasyapps.com/blog/2016/2/8/how-to-use-use-nsnumberformatter-in-swift-to-make-currency-currency-numbers-easy-to-read-to-Read“ rel =“ nofollow noreferrer”>如何使用Swift中的NumberFormatter(NSnumberFormatter)使货币数字易于阅读,

    因此在您的情况下是:

    let formatter = NumberFormatter()
    formatter.currencyCode = "ARS"
    formatter.numberStyle = .currency
    formatter.locale = Locale(identifier: "es_AR")
    print(formatter.string(from: NSNumber(value: 59.00)) ?? "na")
    

    Forcing a Custom Locale

    To display currency, you will need to show the currency symbol ($, €, ¥, £) for the current locale.

    NumberFormatter will show the correct symbol, and the formatting that you might not realize is very different from what you're used to. Different countries use different decimal separators and grouping separators—take a look!

  • In the USA: $3,490,000.89
  • In France: 3 490 000,89 €
  • In Germany: 3.490.000,89 €
  • See: How to Use NumberFormatter (NSNumberFormatter) in Swift to Make Currency Numbers Easy to Read

    So in your case it would be:

    let formatter = NumberFormatter()
    formatter.currencyCode = "ARS"
    formatter.numberStyle = .currency
    formatter.locale = Locale(identifier: "es_AR")
    print(formatter.string(from: NSNumber(value: 59.00)) ?? "na")
    
    请恋爱 2025-02-17 09:46:15

    尝试以下尝试:

    let formatter = NumberFormatter()
    formatter.numberStyle = .currency
    formatter.locale = Locale(identifier: "es_AR")
    print(formatter.string(from: NSNumber(value: 59.00)) ?? "na")
    

    在此处检查本地标识符: https://gist.github.com/jacobbubu/jacobbubu/1836273

    Try this:

    let formatter = NumberFormatter()
    formatter.numberStyle = .currency
    formatter.locale = Locale(identifier: "es_AR")
    print(formatter.string(from: NSNumber(value: 59.00)) ?? "na")
    

    check the local identifier here: https://gist.github.com/jacobbubu/1836273

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文