Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 674
Andrey Kuznetsov Avatar asked Jun 05 '10 11:06

Andrey Kuznetsov


1 Answers

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)
like image 155
Slobodan Kovacevic Avatar answered Sep 19 '22 07:09

Slobodan Kovacevic