简体   繁体   English

铁路不同的货币格式

[英]rails different currency formats

I need to show user amount presented in different currencies. 我需要显示以不同货币呈现的用户数量。 eq : eq:

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

So I need to use number_to_currency three times with different locales(en, eu, ru). 所以我需要使用不同语言环境(en,eu,ru)三次使用number_to_currency What is the right way to do it? 做正确的方法是什么?

I don't think you actually need different locales, because you have just balances in different currencies. 我认为您实际上不需要不同的区域设置,因为您只有不同货币的余额。 You can simply pass additional arguments to number_to_currency. 您可以简单地将其他参数传递给number_to_currency。 Something like this: 像这样的东西:

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

This will display: € 70 000.00 这将显示:€70 000.00

Additionally it seems that you can set :locale option when calling number_to_currency. 此外,您似乎可以在调用number_to_currency时设置:locale选项。 It's not documented, but here is the part of the number_to_currency code: 它没有记录,但这里是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 {}

So you should be able to do something like: 所以你应该能够做到这样的事情:

 number_to_currency(70000.00, :locale => :ru)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM