Skip to content

Commit

Permalink
Merge pull request rails#6512 from jaredbeck/fix_number_to_currency_n…
Browse files Browse the repository at this point in the history
…eg_format

Fix handling of negative zero in number_to_currency
  • Loading branch information
josevalim committed May 28, 2012
2 parents 135f620 + 371508c commit 5acb10d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/number_helper.rb
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions activesupport/test/number_helper_test.rb
Expand Up @@ -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

Expand Down

0 comments on commit 5acb10d

Please sign in to comment.