Class: Float
- Defined in:
- lib/vendor/backports-3.3.5/lib/backports/1.9.1/float/round.rb
Constant Summary collapse
- INFINITY =
1.0/0.0
- NAN =
0.0/0.0
Instance Method Summary collapse
Instance Method Details
#round_with_digits(ndigits = 0) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vendor/backports-3.3.5/lib/backports/1.9.1/float/round.rb', line 5 def round_with_digits(ndigits=0) ndigits = Backports::coerce_to_int(ndigits) case when ndigits == 0 round_without_digits when ndigits < 0 p = 10 ** -ndigits p > abs ? 0 : (self / p).round * p else p = 10 ** ndigits prod = self * p prod.infinite? || prod.nan? ? self : prod.round.to_f / p end end |