Skip to content

Instantly share code, notes, and snippets.

@caius
Created August 24, 2009 21:16
Show Gist options
  • Save caius/174198 to your computer and use it in GitHub Desktop.
Save caius/174198 to your computer and use it in GitHub Desktop.
module ExtendNumericRounding
def roundup(nearest=10)
self % nearest == 0 ? self : self + nearest - (self % nearest)
end
def rounddown(nearest=10)
self % nearest == 0 ? self : self - (self % nearest)
end
def roundnearest(nearest=10)
up = roundup(nearest)
down = rounddown(nearest)
if (up-self) <= (self-down)
return up
else
return down
end
end
end
Numeric.send(:include, ExtendNumericRounding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment