Dart double operator-truncating-division
Syntax & Examples
double.operator-truncating-division operator
The `~/` operator is used for truncating division, which divides one number by another and returns the integer result by discarding any fractional digits.
Syntax of double.operator-truncating-division
The syntax of double.operator-truncating-division operator is:
operator ~/(num other) → int
This operator-truncating-division operator of double truncating division operator.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
other | required | the number by which this number will be divided |
✐ Examples
1 Truncate divide two numbers (10.0 ~/ 3.0)
In this example,
- We use the `~/` operator to perform truncating division of
10.0
by3.0
. - The result is stored in the variable
result
. - We print the result to standard output.
Dart Program
void main() {
double result = 10.0 ~/ 3.0;
print('Result: $result');
}
Output
Result: 3
2 Truncate divide two variables (a ~/ b)
In this example,
- We define two variables
a
andb
with values15.0
and4.0
respectively. - We then use the `~/` operator to perform truncating division of
a
byb
. - The result is stored in the variable
result
. - We print the result to standard output.
Dart Program
void main() {
double a = 15.0;
double b = 4.0;
int result = a ~/ b;
print('Result: $result');
}
Output
Result: 3
3 Truncate divide a negative number by a positive number (-20.0 ~/ 4.0)
In this example,
- We use the `~/` operator to perform truncating division of
-20.0
by4.0
. - The result is stored in the variable
result
. - We print the result to standard output.
Dart Program
void main() {
double result = -20.0 ~/ 4.0;
print('Result: $result');
}
Output
Result: -5
Summary
In this Dart tutorial, we learned about operator-truncating-division operator of double: the syntax and few working examples with output and detailed explanation for each example.