roundedDiv method
Divides this by denominator and rounds the result using the specified mode
The rounding behavior varies based on the mode:
floor: Rounds down to the next lower integerceil: Rounds up to the next higher integertruncate: Rounds towards zero (removes the fractional part)up: Rounds away from zero, increasing the magnitude of the quotienthalfUp: Rounds to the nearest integer, rounding up on tieshalfDown: Rounds to the nearest integer, rounding down on tieshalfEven: Rounds to the nearest integer; if exactly halfway, rounds to the nearest even integer
Example:
print(BigInt.from(11).roundedDiv(BigInt.from(3), RoundingMode.floor)); // 11 / 3 --> 3
print(BigInt.from(10).roundedDiv(BigInt.from(3), RoundingMode.ceil)); // 10 / 3 --> 4
print(BigInt.from(11).roundedDiv(BigInt.from(3), RoundingMode.truncate)); // 11 / 3 --> 3
print(BigInt.from(-10).roundedDiv(BigInt.from(3), RoundingMode.truncate)); // -11 / 3 --> -3
print(BigInt.from(10).roundedDiv(BigInt.from(3), RoundingMode.up)); // 10 / 3 --> 4
print(BigInt.from(-10).roundedDiv(BigInt.from(2), RoundingMode.up)); // -10 / 3 --> -4
print(BigInt.from(7).roundedDiv(BigInt.from(2), RoundingMode.halfUp)); // 7 / 2 --> 4
print(BigInt.from(7).roundedDiv(BigInt.from(2), RoundingMode.halfDown)); // 7 / 2 --> 3
print(BigInt.from(7).roundedDiv(BigInt.from(2), RoundingMode.halfEven)); // 7 / 2 --> 4
print(BigInt.from(5).roundedDiv(BigInt.from(2), RoundingMode.halfEven)); // 5 / 2 --> 2
print(BigInt.from(6).roundedDiv(BigInt.from(2), RoundingMode.halfEven)); // 6 / 2 --> 3
denominator: The divisormode: The rounding mode to apply- Returns: The rounded quotient as a
BigInt
Implementation
BigInt roundedDiv(BigInt denominator, RoundingMode mode) {
final Rational value = Rational(this, denominator);
return value.rounded(mode).toBigInt();
}