Dart double remainder()
Syntax & Examples
double.remainder() method
The `remainder` method in Dart returns the remainder of the truncating division of the given number by another number.
Syntax of double.remainder()
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
.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
other | required | the divisor |
Return Type
double.remainder() returns value of type double
.
✐ Examples
1 Calculate remainder of division
In this example,
- We create a double variable
num
with the value 10.0 and a double variabledivisor
with the value 3.0. - We use the
remainder()
method onnum
withdivisor
as the argument to calculate the remainder of the division. - We then print the result to standard output.
Dart Program
void main() {
double num = 10.0;
double divisor = 3.0;
double result = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $result');
}
Output
Remainder of 10.0 divided by 3: 1
2 Calculate remainder of division with decimal numbers
In this example,
- We create a double variable
num
with the value 17.5 and a double variabledivisor
with the value 2.5. - We use the
remainder()
method onnum
withdivisor
as the argument to calculate the remainder of the division. - We then print the result to standard output.
Dart Program
void main() {
double num = 17.5;
double divisor = 2.5;
double result = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $result');
}
Output
Remainder of 17.5 divided by 2.5: 0
3 Calculate remainder of division with a negative number
In this example,
- We create a double variable
num
with the value -10.0 and a double variabledivisor
with the value 3.0. - We use the
remainder()
method onnum
withdivisor
as the argument to calculate the remainder of the division. - We then print the result to standard output.
Dart Program
void main() {
double num = -10.0;
double divisor = 3.0;
double result = num.remainder(divisor);
print('Remainder of $num divided by $divisor: $result');
}
Output
Remainder of -10.0 divided by 3: -1
Summary
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.