diff options
author | José Valim <jose.valim@gmail.com> | 2012-05-28 01:52:40 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-05-28 01:52:40 -0700 |
commit | 5acb10d6c359f9b715e5b5a5d26a524581a9ac41 (patch) | |
tree | b392a6621de630079df0c901d9a74c462bd2dc01 /activesupport | |
parent | 135f620535d94af262d11f62bb814a2010701b1d (diff) | |
parent | 371508c240f556539ce8891b05e8715f546b0e4d (diff) | |
download | rails-5acb10d6c359f9b715e5b5a5d26a524581a9ac41.tar.gz rails-5acb10d6c359f9b715e5b5a5d26a524581a9ac41.tar.bz2 rails-5acb10d6c359f9b715e5b5a5d26a524581a9ac41.zip |
Merge pull request #6512 from jaredbeck/fix_number_to_currency_neg_format
Fix handling of negative zero in number_to_currency
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/number_helper.rb | 2 | ||||
-rw-r--r-- | activesupport/test/number_helper_test.rb | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index 8f5309c824..981ab0cb36 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -111,7 +111,7 @@ module ActiveSupport unit = options.delete(:unit) format = options.delete(:format) - if number.to_f < 0 + if number.to_f.phase != 0 format = options.delete(:negative_format) number = number.respond_to?("abs") ? number.abs : number.sub(/^-/, '') end diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 8bcdea7ce6..9b7d7f020c 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -64,6 +64,8 @@ module ActiveSupport assert_equal("$1,234,567,890.50", number_helper.number_to_currency("1234567890.50")) assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"})) assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", {:unit => "Kč", :format => "%n %u", :negative_format => "%n - %u"})) + assert_equal("0.00", number_helper.number_to_currency(+0.0, {:unit => "", :negative_format => "(%n)"})) + assert_equal("(0.00)", number_helper.number_to_currency(-0.0, {:unit => "", :negative_format => "(%n)"})) end end |