Merge pull request #5609 from tjmcewan/master

prevent returning a negative zero from number_with_precision
This commit is contained in:
José Valim 2012-03-27 03:05:11 -07:00
commit 19901c6c61
2 changed files with 2 additions and 0 deletions

View File

@ -292,6 +292,7 @@ module ActionView
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

View File

@ -96,6 +96,7 @@ class NumberHelperTest < ActionView::TestCase
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