mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
fixes an issue with number_to_human when converting values which are less than 1 but greater than -1 [#6576 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
committed by
Santiago Pastorino
parent
e8458d37c5
commit
0eae625256
@@ -472,7 +472,7 @@ module ActionView
|
||||
end.keys.map{|e_name| inverted_du[e_name] }.sort_by{|e| -e}
|
||||
|
||||
number_exponent = number != 0 ? Math.log10(number.abs).floor : 0
|
||||
display_exponent = unit_exponents.find{|e| number_exponent >= e }
|
||||
display_exponent = unit_exponents.find{ |e| number_exponent >= e } || 0
|
||||
number /= 10 ** display_exponent
|
||||
|
||||
unit = case units
|
||||
|
||||
@@ -195,7 +195,9 @@ class NumberHelperTest < ActionView::TestCase
|
||||
|
||||
def test_number_to_human
|
||||
assert_equal '-123', number_to_human(-123)
|
||||
assert_equal '0', number_to_human(0)
|
||||
assert_equal '-0.5', number_to_human(-0.5)
|
||||
assert_equal '0', number_to_human(0)
|
||||
assert_equal '0.5', number_to_human(0.5)
|
||||
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