Division Operator that returns Integer Quotient
Dart Arithmetic Division Operator (returning an integer result) takes two numbers as operands and returns the quotient (integer) for the division of left operand by right operand.
Symbol
~/
symbol is used for Division Operator (returning an integer result).
Syntax
The syntax for Division Operator (returning an integer result) is
operand_1 ~/ operand_2
The operands must be numbers.
Examples
In the following example, we take two integers:n1
and n2
, and find the quotient of the division n1 / n2
using Arithmetic Division Operator (returning an integer result).
main.dart
void main() {
var n1 = 14;
var n2 = 3;
var output = n1 ~/ n2;
print('n1 ~/ n2 = $output');
}
Output
n1 ~/ n2 = 4
In the following example, we divide a value of type double by a value of type integer.
main.dart
void main() {
var n1 = 14.89;
var n2 = 3;
var output = n1 ~/ n2;
print('n1 ~/ n2 = $output');
}
Output
n1 ~/ n2 = 4
Conclusion
In this Dart Tutorial, we learned how to use Division Operator (returning an integer result) to find the quotient (an integer) in the division operation of given two numbers.