views:

48

answers:

1

Hello everybody. 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 times with different locales(en, eu, ru). What is the right way to do it?

+3  A: 

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)
Slobodan Kovacevic
I need to show 30 more currencies and I think there is some way to switch default locale in rails...
SMiX
@SMiX I modified my answer to include :locale option.
Slobodan Kovacevic
It works! Thanks. There is not this option in official documentation.
SMiX