开发者

rails different currency formats

I need to show user amount presented in different currencies. e.q. :

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

So I need to use number_to_currency three 开发者_JAVA技巧times with different locales(en, eu, ru). 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. Something like this:

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

This will display: € 70 000.00

Additionally it seems that you can set :locale option when calling number_to_currency. It's not documented, but here is the part of the number_to_currency code:

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜