Skip to content
Browse files

Merge pull request #6512 from jaredbeck/fix_number_to_currency_neg_fo…

…rmat

Fix handling of negative zero in number_to_currency
  • Loading branch information...
2 parents 135f620 + 371508c commit 5acb10d6c359f9b715e5b5a5d26a524581a9ac41 @josevalim josevalim committed May 28, 2012
Showing with 3 additions and 1 deletion.
  1. +1 −1 activesupport/lib/active_support/number_helper.rb
  2. +2 −0 activesupport/test/number_helper_test.rb
View
2 activesupport/lib/active_support/number_helper.rb
@@ -111,7 +111,7 @@ def number_to_currency(number, options = {})
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
View
2 activesupport/test/number_helper_test.rb
@@ -64,6 +64,8 @@ def test_number_to_currency
assert_equal("$1,234,567,890.50", number_helper.number_to_currency("1234567890.50"))
assert_equal("1,234,567,890.50 K&#269;", number_helper.number_to_currency("1234567890.50", {:unit => "K&#269;", :format => "%n %u"}))
assert_equal("1,234,567,890.50 - K&#269;", number_helper.number_to_currency("-1234567890.50", {:unit => "K&#269;", :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

0 comments on commit 5acb10d

Please sign in to comment.
Something went wrong with that request. Please try again.