rafaelss (owner)

Revisions

gist: 66152 Download_button fork
public
Public Clone URL: git://gist.github.com/66152.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# extracted from
# http://www.codecodex.com/wiki/index.php?title=Round_a_number_to_a_specific_decimal_place#Ruby
class Float
  def round_to(x)
    (self * 10**x).round.to_f / 10**x
  end
 
  def ceil_to(x)
    (self * 10**x).ceil.to_f / 10**x
  end
 
  def floor_to(x)
    (self * 10**x).floor.to_f / 10**x
  end
end