提交 378c8d2c 编写于 作者: Y Yves Senn

fix `number_to_percentage` with `Float::NAN`, `Float::INFINITY`.

Closes #14405.

This is a follow-up to 9e997e90 to restore
the documented behavior.
上级 a0c1c18e
* `number_to_percentage` does not crash with `Float::NAN` or `Float::INFINITY`
as input.
Fixes #14405.
*Yves Senn*
* Add `include_hidden` option to `collection_check_boxes` helper.
*Vasiliy Ermolovich*
......
......@@ -32,6 +32,9 @@ def test_number_to_percentage
assert_equal "100%", number_to_percentage(100, precision: 0)
assert_equal "123.4%", number_to_percentage(123.400, precision: 3, strip_insignificant_zeros: true)
assert_equal "1.000,000%", number_to_percentage(1000, delimiter: ".", separator: ",")
assert_equal "98a%", number_to_percentage("98a")
assert_equal "NaN%", number_to_percentage(Float::NAN)
assert_equal "Inf%", number_to_percentage(Float::INFINITY)
end
def test_number_with_delimiter
......
......@@ -32,8 +32,7 @@ def convert
end
formatted_string =
case rounded_number
when BigDecimal
if BigDecimal === rounded_number && rounded_number.finite?
s = rounded_number.to_s('F') + '0'*precision
a, b = s.split('.', 2)
a + '.' + b[0, precision]
......
......@@ -79,6 +79,9 @@ def test_number_to_percentage
assert_equal("123.4%", number_helper.number_to_percentage(123.400, :precision => 3, :strip_insignificant_zeros => true))
assert_equal("1.000,000%", number_helper.number_to_percentage(1000, :delimiter => '.', :separator => ','))
assert_equal("1000.000 %", number_helper.number_to_percentage(1000, :format => "%n %"))
assert_equal("98a%", number_helper.number_to_percentage("98a"))
assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN))
assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY))
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册