The `remainder` method in Dart returns the remainder of the truncating division of the given number by another number.
The syntax of double.remainder() method is:
double remainder(num other)
This remainder() method of double returns the remainder of the truncating division of this
by other
.
Parameter | Optional/Required | Description |
---|---|---|
other | required | the divisor |
double.remainder() returns value of type double
.
In this example,
num
with the value 10.0 and a double variable divisor
with the value 3.0.remainder()
method on num
with divisor
as the argument to calculate the remainder of the division.void main() {
double num = 10.0;
double divisor = 3.0;
double result = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $result');
}
Remainder of 10.0 divided by 3: 1
In this example,
num
with the value 17.5 and a double variable divisor
with the value 2.5.remainder()
method on num
with divisor
as the argument to calculate the remainder of the division.void main() {
double num = 17.5;
double divisor = 2.5;
double result = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $result');
}
Remainder of 17.5 divided by 2.5: 0
In this example,
num
with the value -10.0 and a double variable divisor
with the value 3.0.remainder()
method on num
with divisor
as the argument to calculate the remainder of the division.void main() {
double num = -10.0;
double divisor = 3.0;
double result = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $result');
}
Remainder of -10.0 divided by 3: -1
In this Dart tutorial, we learned about remainder() method of double: the syntax and few working examples with output and detailed explanation for each example.