bia-fitness/lifting/utils.py

12 lines
315 B
Python
Raw Normal View History

2015-04-06 18:53:17 +00:00
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