Created
February 18, 2009 02:47
-
-
Save rafaelss/66152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment