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

ParameterOptional/RequiredDescription
otherrequiredthe BigInt divisor

Return Type

BigInt.remainder() returns value of type BigInt.



✐ Examples

1 Calculate remainder of positive dividend and divisor

In this example,

  1. We define a positive dividend BigInt dividend with a value of 10 and a positive divisor BigInt divisor with a value of 3.
  2. We use the remainder() method to calculate the remainder of the division of dividend by divisor.
  3. 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,

  1. We define a negative dividend BigInt dividend with a value of -10 and a positive divisor BigInt divisor with a value of 3.
  2. We use the remainder() method to calculate the remainder of the division of dividend by divisor.
  3. 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,

  1. We define a positive dividend BigInt dividend with a value of 10 and a negative divisor BigInt divisor with a value of -3.
  2. We use the remainder() method to calculate the remainder of the division of dividend by divisor.
  3. 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.