fix rounding routine to consider constraints