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](/_next/image?url=https%3A%2F%2Ffirebasestorage.googleapis.com%2Fv0%2Fb%2Fyayo-code-blog-prod.appspot.com%2Fo%2Flocales%252Fen%252Fposts%252Fc5pxmCgk2pv5ubCmZsOC%252F23e4382a-6f19-4d19-99f6-ef052f2cd74f.png%3Falt%3Dmedia%26token%3D1f62f3da-4e38-4e20-aa80-9f946c5c4cfd&w=800&q=75)
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: