One of the nicest things in the built-in Rails internationalization features is the ability to format the currency according to the local culture (the number_to_currency method). For example, many european contries use ‘,’ as a separator and ‘.’ as a delimiter.
However, the examples presented in the help page (http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#M001684) are missing something essential.
number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "")
# => £1234567890,50
number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "", :format => "%n %u")
# => 1234567890,50 £
Why should i need a helper method where i can set all those parameters by hand?
Digging in the source code, i found how those settings can be put in the locale yml config file. Below is an example from my french localization file.
fr:
number:
currency:
format:
delimiter: ','
separator: '.'
precision: 2
format: '%n %u'
Filed under: ActiveRecord, Internationalization, ruby-on-rails | Tagged: currency, i11n, internationalization, number_to_currency, rails, ruby | Leave a comment »