Class: Float

### Home Classes Methods

### In Files

- lib/backports/1.9.1/float/round.rb

### Parent

Object

### Methods

- #round_with_digits

### Class/Module Index

Quicksearch

- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator
- Backports
- Backports::MOST_EXTREME_OBJECT_EVER
- Backports::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Random
- Random::Implementation
- Random::MT19937
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# Float

### Public Instance Methods

round_with_digits(ndigits=0) click to toggle source

    # File 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.