### Home Classes Methods

### In Files

- lib/facets/numeric/round.rb

### Parent

Object

### Methods

- #round_at
- #round_to

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Lazy
- Lazy::Future
- Lazy::Promise
- Lazy::Promise::DIVERGES
- Lazy::PromiseSafe
- Enumerable
- Enumerable::Recursor
- Method
- Method::Composition
- Module
- Module::InstanceFunction
- Array
- Binding
- Class
- Comparable
- Denumerable
- Denumerator
- Dir
- Enumerator
- Exception
- Facets
- FalseClass
- File
- FileTest
- Fixnum
- Float
- Functor
- Hash
- Indexable
- Instance
- Integer
- Kernel
- MatchData
- NA
- NilClass
- Numeric
- Object
- ObjectSpace
- Proc
- Process
- Range
- Regexp
- String
- Struct
- Symbol
- Time
- TrueClass
- UnboundMethod

No matching classes.

# Float

class Integer

    # See Float#round_at.

    def round_at(*args)
      to_f.round_at(*args)
    end

    # See Float#round_to.

    def round_to(*args)
      to_f.round_to(*args)
    end

end

### Public Instance Methods

round_at( d ) click to toggle source

Rounds to the given decimal position.

    4.555.round_at(0)  #=> 5.0
    4.555.round_at(1)  #=> 4.6
    4.555.round_at(2)  #=> 4.56
    4.555.round_at(3)  #=> 4.555

CREDIT: Trans

    # File lib/facets/numeric/round.rb, line 50
    def round_at( d ) #d=0
      (self * (10.0 ** d)).round.to_f / (10.0 ** d)
    end

round_to( n ) click to toggle source

Rounds to the nearest _n_th degree.

    4.555.round_to(1)     #=> 5.0
    4.555.round_to(0.1)   #=> 4.6
    4.555.round_to(0.01)  #=> 4.56
    4.555.round_to(0)     #=> 4.555

CREDIT: Trans

    # File lib/facets/numeric/round.rb, line 63
    def round_to( n ) #n=1
      return self if n == 0
      (self * (1.0 / n)).round.to_f / (1.0 / n)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.