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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With