gpt4 book ai didi

ruby-on-rails - rails 不同的货币格式

转载 作者:行者123 更新时间:2023-12-04 07:29:36 26 4
gpt4 key购买 nike

我需要显示以不同货币表示的用户金额。例如:

Your balance: $ 100 000.00
€ 70 000.00
3 000 000,00 руб.

所以我需要使用 number_to_currency使用不同的语言环境(en、eu、ru)三遍。正确的做法是什么?

最佳答案

我认为您实际上不需要不同的语言环境,因为您只有不同货币的余额。您可以简单地将附加参数传递给 number_to_currency。像这样的东西:

number_to_currency(70000.00, :unit => "€", :separator => ".", :delimiter => " ", :format => "%u %n")

这将显示:€70 000.00

此外,您似乎可以在调用 number_to_currency 时设置 :locale 选项。它没有记录,但这里是 number_to_currency 代码的一部分:
defaults  = I18n.translate('number.format''number.format', :locale => options[:locale], :raise => true) rescue {}
currency = I18n.translate('number.currency.format''number.currency.format', :locale => options[:locale], :raise => true) rescue {}

因此,您应该能够执行以下操作:
 number_to_currency(70000.00, :locale => :ru)

关于ruby-on-rails - rails 不同的货币格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2980077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com