Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Created February 18, 2009 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelss/66152 to your computer and use it in GitHub Desktop.
Save rafaelss/66152 to your computer and use it in GitHub Desktop.
# 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