Permalink
Browse files

Merge pull request #4311 from kuroda/3-2-negative_format

Infer currency negative format from positive one. (3-2-stable)
  • Loading branch information...
2 parents d268ef2 + 22f901c commit 867a7927ae0d4dc1c5d882de81c7f8e3c11ce692 @tenderlove tenderlove committed Jan 5, 2012
View
1 actionpack/lib/action_view/helpers/number_helper.rb
@@ -128,6 +128,7 @@ def number_to_currency(number, options = {})
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
currency = I18n.translate(:'number.currency.format', :locale => options[:locale], :default => {})
+ currency[:negative_format] ||= "-" + currency[:format] if currency[:format]
defaults = DEFAULT_CURRENCY_VALUES.merge(defaults).merge!(currency)
defaults[:negative_format] = "-" + options[:format] if options[:format]
View
7 actionpack/test/template/number_helper_i18n_test.rb
@@ -53,6 +53,13 @@ def test_number_to_currency_with_clean_i18n_settings
assert_equal("-$10.00", number_to_currency(-10))
end
end
+
+ def test_number_to_currency_without_currency_negative_format
+ clean_i18n do
+ I18n.backend.store_translations 'ts', :number => { :currency => { :format => { :unit => '@', :format => '%n %u' } } }
+ assert_equal("-10.00 @", number_to_currency(-10, :locale => 'ts'))
+ end
+ end
def test_number_with_i18n_precision
#Delimiter was set to ""

0 comments on commit 867a792

Please sign in to comment.