mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
change number_with_precision to not return negative zeros
This commit is contained in:
parent
ded74dfd8b
commit
7051a234b7
2 changed files with 2 additions and 0 deletions
|
@ -292,6 +292,7 @@ module ActionView
|
||||||
precision = precision > 0 ? precision : 0 #don't let it be negative
|
precision = precision > 0 ? precision : 0 #don't let it be negative
|
||||||
else
|
else
|
||||||
rounded_number = BigDecimal.new(number.to_s).round(precision).to_f
|
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
|
end
|
||||||
formatted_number = number_with_delimiter("%01.#{precision}f" % rounded_number, options)
|
formatted_number = number_with_delimiter("%01.#{precision}f" % rounded_number, options)
|
||||||
if strip_insignificant_zeros
|
if strip_insignificant_zeros
|
||||||
|
|
|
@ -96,6 +96,7 @@ class NumberHelperTest < ActionView::TestCase
|
||||||
assert_equal("0.001", number_with_precision(0.00111, :precision => 3))
|
assert_equal("0.001", number_with_precision(0.00111, :precision => 3))
|
||||||
assert_equal("10.00", number_with_precision(9.995, :precision => 2))
|
assert_equal("10.00", number_with_precision(9.995, :precision => 2))
|
||||||
assert_equal("11.00", number_with_precision(10.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
|
end
|
||||||
|
|
||||||
def test_number_with_precision_with_custom_delimiter_and_separator
|
def test_number_with_precision_with_custom_delimiter_and_separator
|
||||||
|
|
Loading…
Reference in a new issue