def iround(val, lower):
	"""Round value to lower or upper integer in case of the equally good fit.
	Equas to math.round for lower = False.

	val: float  - the value to be rounded
	lower: bool  - direction of the rounding resolution in case of the equally good fit

	return  v: int  - rounded value

	>>> iround(2.5, True)
	2
	>>> iround(2.5, False)
	3
	>>> iround(2.2, True)
	2
	>>> iround(2.2, False)
	2
	>>> iround(2.7, True)
	3
	>>> iround(2.7, False)
	3
	"""
	q, r = divmod(val, 1)
	res = int(q if lower and r <= 0.5 or not lower and r < 0.5 else q + 1)
	# print('>> val: {:.3f}, q: {:.0f}, r: {:.3f}, res: {:.0f}'.format(val, q, r-0.5, res), file=sys.stderr)
	return res