|
Versions Of This Snippet::
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: :0.0.1
def round_to_closest_multiple(number, closest_multiple_of)
float = number / closest_multiple_of
float_array = float.to_s.split(".")
closest_multiple = float_array[0].to_i * closest_multiple_of
roundable = number - closest_multiple
if roundable >= ((closest_multiple_of/1.0)/2)
rounded_number = closest_multiple + closest_multiple_of
else
rounded_number = closest_multiple
end
return rounded_number
end
Submit a new versionYou can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..
|
||||||||||||||||||||||||||
