bia-fitness/lifting/utils.py
2015-04-06 14:53:17 -04:00

12 lines
315 B
Python

import decimal
def round_to(number, increment, up_threshold=0.95):
""" round number to nearest multiple of increment """
ratio = number/increment
whole = ratio.to_integral(rounding=decimal.ROUND_DOWN)
dec = ratio - whole
if dec >= up_threshold:
whole += 1
return whole * increment