Skip to content
Browse files

Fix handling of negative zero in number_to_currency

  • Loading branch information...
1 parent 135f620 commit 371508c240f556539ce8891b05e8715f546b0e4d @jaredbeck jaredbeck 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 371508c

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