提交 b80cf265 编写于 作者: B Ben Sharpe 提交者: Santiago Pastorino

Fix number_to_human(0) exception [#5532 state:resolved]

Signed-off-by: NSantiago Pastorino <santiago@wyeworks.com>
上级 708ee9c5
......@@ -459,7 +459,8 @@ def number_to_human(number, options = {})
raise ArgumentError, ":units must be a Hash or String translation scope."
end.keys.map{|e_name| DECIMAL_UNITS.invert[e_name] }.sort_by{|e| -e}
number_exponent = Math.log10(number).floor
number_exponent = 0
number_exponent = Math.log10(number).floor if number != 0
display_exponent = unit_exponents.find{|e| number_exponent >= e }
number /= 10 ** display_exponent
......
......@@ -184,6 +184,7 @@ def test_number_to_human_size_with_custom_delimiter_and_separator
end
def test_number_to_human
assert_equal '0', number_to_human(0)
assert_equal '123', number_to_human(123)
assert_equal '1.23 Thousand', number_to_human(1234)
assert_equal '12.3 Thousand', number_to_human(12345)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册