Dart num remainder()
Syntax & Examples


num.remainder() method

The `remainder` method in Dart returns the remainder of the truncating division of this by another number.


Syntax of num.remainder()

The syntax of num.remainder() method is:

 num remainder(num other) 

This remainder() method of num returns the remainder of the truncating division of this by other.

Parameters

ParameterOptional/RequiredDescription
otherrequiredThe number by which to divide.

Return Type

num.remainder() returns value of type num.



✐ Examples

1 Remainder of integer division

In this example,

  1. We create two num variables, dividend with the value 10 and divisor with the value 3.
  2. We use the remainder() method to find the remainder of dividend divided by divisor.
  3. We then print the result to standard output.

Dart Program

void main() {
  num dividend = 10;
  num divisor = 3;
  num remainderValue = dividend.remainder(divisor);
  print('Remainder of $dividend divided by $divisor: $remainderValue');
}

Output

Remainder of 10 divided by 3: 1

2 Remainder of decimal division

In this example,

  1. We create two num variables, dividend with the value 7.5 and divisor with the value 2.
  2. We use the remainder() method to find the remainder of dividend divided by divisor.
  3. We then print the result to standard output.

Dart Program

void main() {
  num dividend = 7.5;
  num divisor = 2;
  num remainderValue = dividend.remainder(divisor);
  print('Remainder of $dividend divided by $divisor: $remainderValue');
}

Output

Remainder of 7.5 divided by 2: 1.5

Summary

In this Dart tutorial, we learned about remainder() method of num: the syntax and few working examples with output and detailed explanation for each example.