from .math_rational_rational import rational from .math_rational_types import Rational from .math_round_div import RoundingMode, round_div def rational_to_integer(r: Rational, mode: RoundingMode) -> int: """The integer a fraction rounds to, under an explicit rounding mode. This is the point where an exact rate becomes minor units, so the policy is the caller's to state. """ n = rational(r.numerator, r.denominator) return round_div(n.numerator, n.denominator, mode)