toInt method

int toInt([
  1. RoundingMode mode = RoundingMode.truncate
])

Converts this Rational to an int.

By default, truncates toward zero (matching toBigInt() behavior). Optionally accepts a RoundingMode to round before converting.

Example:

print(Rational.parse('7.5').toInt());                          // 3
print(Rational.parse('7.5').toInt(RoundingMode.halfUp));       // 8
print(Rational.parse('-7.5').toInt(RoundingMode.floor));       // -8

Implementation

int toInt([RoundingMode mode = RoundingMode.truncate]) =>
    rounded(mode).toBigInt().toInt();