Skip to content

Commit

Permalink
change number_with_precision to not return negative zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmcewan committed Mar 27, 2012
1 parent ded74df commit 7051a23
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_view/helpers/number_helper.rb
Expand Up @@ -292,6 +292,7 @@ def number_with_precision(number, options = {})
precision = precision > 0 ? precision : 0 #don't let it be negative
else
rounded_number = BigDecimal.new(number.to_s).round(precision).to_f
rounded_number = rounded_number.zero? ? rounded_number.abs : rounded_number #prevent showing negative zeros
end
formatted_number = number_with_delimiter("%01.#{precision}f" % rounded_number, options)
if strip_insignificant_zeros
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/template/number_helper_test.rb
Expand Up @@ -96,6 +96,7 @@ def test_number_with_precision
assert_equal("0.001", number_with_precision(0.00111, :precision => 3))
assert_equal("10.00", number_with_precision(9.995, :precision => 2))
assert_equal("11.00", number_with_precision(10.995, :precision => 2))
assert_equal("0.00", number_with_precision(-0.001, :precision => 2))
end

def test_number_with_precision_with_custom_delimiter_and_separator
Expand Down

0 comments on commit 7051a23

Please sign in to comment.