mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42341 from zzak/zzak/42316
NumberToRoundedConverter should handle -Float::INFINITY
This commit is contained in:
commit
ee8134d6f9
2 changed files with 5 additions and 5 deletions
|
@ -20,11 +20,7 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
formatted_string =
|
||||
if rounded_number.nan?
|
||||
"NaN"
|
||||
elsif rounded_number.infinite?
|
||||
"Inf"
|
||||
else
|
||||
if rounded_number.finite?
|
||||
s = rounded_number.to_s("F")
|
||||
a, b = s.split(".", 2)
|
||||
if precision != 0
|
||||
|
@ -33,6 +29,9 @@ module ActiveSupport
|
|||
a << b[0, precision]
|
||||
end
|
||||
a
|
||||
else
|
||||
# Infinity/NaN
|
||||
"%f" % rounded_number
|
||||
end
|
||||
else
|
||||
formatted_string = rounded_number
|
||||
|
|
|
@ -208,6 +208,7 @@ module ActiveSupport
|
|||
assert_equal "9775." + "0" * 96, number_helper.number_to_rounded("9775", precision: 100, significant: true)
|
||||
assert_equal("97.7", number_helper.number_to_rounded(Rational(9772, 100), precision: 3, significant: true))
|
||||
assert_equal "28729870200000000000000", number_helper.number_to_rounded(0.287298702e23.to_d, precision: 0, significant: true)
|
||||
assert_equal "-Inf", number_helper.number_to_rounded(-Float::INFINITY, precision: 0, significant: true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue