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

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
Ben Sharpe
2010-09-02 08:05:23 -07:00
committed by Santiago Pastorino
parent 708ee9c5ac
commit b80cf265be
2 changed files with 3 additions and 1 deletions

View File

@@ -459,7 +459,8 @@ module ActionView
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

View File

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