Skip to content

Commit 371508c

Browse files
committed
Fix handling of negative zero in number_to_currency
1 parent 135f620 commit 371508c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

activesupport/lib/active_support/number_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def number_to_currency(number, options = {})
111111
unit = options.delete(:unit)
112112
format = options.delete(:format)
113113

114-
if number.to_f < 0
114+
if number.to_f.phase != 0
115115
format = options.delete(:negative_format)
116116
number = number.respond_to?("abs") ? number.abs : number.sub(/^-/, '')
117117
end

activesupport/test/number_helper_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def test_number_to_currency
6464
assert_equal("$1,234,567,890.50", number_helper.number_to_currency("1234567890.50"))
6565
assert_equal("1,234,567,890.50 K&#269;", number_helper.number_to_currency("1234567890.50", {:unit => "K&#269;", :format => "%n %u"}))
6666
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"}))
67+
assert_equal("0.00", number_helper.number_to_currency(+0.0, {:unit => "", :negative_format => "(%n)"}))
68+
assert_equal("(0.00)", number_helper.number_to_currency(-0.0, {:unit => "", :negative_format => "(%n)"}))
6769
end
6870
end
6971

0 commit comments

Comments
 (0)