Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit b80cf265be083b158c915ccbb4af7ce5ac05aec7 1 parent 708ee9c
@bsharpe bsharpe authored spastorino committed
View
3  actionpack/lib/action_view/helpers/number_helper.rb
@@ -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
View
1  actionpack/test/template/number_helper_test.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.