re-implement integer rounding with explicit handling for div by zero