Skip to content

Commit

Permalink
Fix number_to_human(0) exception [#5532 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
bsharpe authored and spastorino committed Sep 5, 2010
1 parent f0113e5 commit 935fa9d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/helpers/number_helper.rb
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions actionpack/test/template/number_helper_test.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 935fa9d

Please sign in to comment.