code: def roundClosestValid(val, res, decimals=None):
          
          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