Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change number_with_precision to not return negative zeros

  • Loading branch information...
commit 7051a234b7b2f6d7db5b29b3afc7167a8b6db991 1 parent ded74df
Tim McEwan tjmcewan authored
1  actionpack/lib/action_view/helpers/number_helper.rb
View
@@ -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
1  actionpack/test/template/number_helper_test.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.