Module: Polyfill::V2_4::Float
- Defined in:
- lib/polyfill/v2_4/float.rb
Instance Method Summary collapse
Instance Method Details
#ceil(ndigits = 0) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/polyfill/v2_4/float.rb', line 4 def ceil(ndigits = 0) ndigits = InternalUtils.to_int(ndigits) return super() if ndigits == 0 if ndigits > 0 place = 10**ndigits (self * place).ceil / place.to_f else place = 10**-ndigits (self / place).ceil * place end end |
#floor(ndigits = 0) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/polyfill/v2_4/float.rb', line 17 def floor(ndigits = 0) ndigits = InternalUtils.to_int(ndigits) return super() if ndigits == 0 if ndigits > 0 place = 10**ndigits (self * place).floor / place.to_f else place = 10**-ndigits (self / place).floor * place end end |
#truncate(ndigits = 0) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/polyfill/v2_4/float.rb', line 30 def truncate(ndigits = 0) ndigits = InternalUtils.to_int(ndigits) return super() if ndigits == 0 if ndigits > 0 place = 10**ndigits (self * place).truncate / place.to_f else place = 10**-ndigits (self / place).truncate * place end end |