Flutter: Arithmetic operators
The arithmetic operators allow us to do basic math like addition, subtraction, division, etc. Dart supports the following operators:
Name | Operador |
---|---|
Addition | + |
Subtraction | - |
Multiplication | * |
Division | / |
Division with integer result | ~/ |
Modulus | % |
Everything should be fine with how addition, subtraction, multiplication, and division work. But what about the Modulus and the Division with integer result? Let's take a look at what they do:
Modulus %
The result of the modulus %
operator is the reminder of the division, for example:
print( 16 % 3 );
// Result is 1
Parts of the division
Division with integer result ~/
The result of division with integer result ~/
will return only the integer number and discard the decimal numbers, for example:
print( 16 ~/ 3 );
// Result is 5
Examples in DartPad
Run the examples on DartPad: