mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fix number_to_human(0) exception [#5532 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
committed by
Santiago Pastorino
parent
708ee9c5ac
commit
b80cf265be
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user