Dart BigInt remainder()
Syntax & Examples
BigInt.remainder() method
The `remainder()` method returns the remainder of the truncating division of this BigInt by another BigInt.
Syntax of BigInt.remainder()
The syntax of BigInt.remainder() method is:
BigInt remainder(BigInt other) This remainder() method of BigInt returns the remainder of the truncating division of this by other.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the BigInt divisor |
Return Type
BigInt.remainder() returns value of type BigInt.
✐ Examples
1 Calculate remainder of positive dividend and divisor
In this example,
- We define a positive dividend BigInt
dividendwith a value of10and a positive divisor BigIntdivisorwith a value of3. - We use the
remainder()method to calculate the remainder of the division ofdividendbydivisor. - We print the remainder to standard output.
Dart Program
void main() {
BigInt dividend = BigInt.from(10);
BigInt divisor = BigInt.from(3);
BigInt remainder = dividend.remainder(divisor);
print('Remainder of 10 divided by 3: $remainder');
}Output
Remainder of 10 divided by 3: 1
2 Calculate remainder of negative dividend and positive divisor
In this example,
- We define a negative dividend BigInt
dividendwith a value of-10and a positive divisor BigIntdivisorwith a value of3. - We use the
remainder()method to calculate the remainder of the division ofdividendbydivisor. - We print the remainder to standard output.
Dart Program
void main() {
BigInt dividend = BigInt.from(-10);
BigInt divisor = BigInt.from(3);
BigInt remainder = dividend.remainder(divisor);
print('Remainder of -10 divided by 3: $remainder');
}Output
Remainder of -10 divided by 3: -1
3 Calculate remainder of positive dividend and negative divisor
In this example,
- We define a positive dividend BigInt
dividendwith a value of10and a negative divisor BigIntdivisorwith a value of-3. - We use the
remainder()method to calculate the remainder of the division ofdividendbydivisor. - We print the remainder to standard output.
Dart Program
void main() {
BigInt dividend = BigInt.from(10);
BigInt divisor = BigInt.from(-3);
BigInt remainder = dividend.remainder(divisor);
print('Remainder of 10 divided by -3: $remainder');
}Output
Remainder of 10 divided by -3: 1
Summary
In this Dart tutorial, we learned about remainder() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.