code: def round_to_fraction(val, res, decimals=None):
      
      if val is None:
          return 0.0
      if decimals is None and "." in str(res):
          decimals = len(str(res).split('.')[1])
  
      return round(round(val / res) * res, decimals)
docs: round to closest resolution