Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL SQLITE MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST DART PLAYWRIGHT TOOLS MATH SHEETS POWER BI

Dart Tutorial

Dart HOME Dart Intro Dart Get Started Dart Syntax Dart Output Dart Comments Dart Variables Dart final and const Dart Data Types Dart Numbers Dart Strings Dart String Interpolation Dart String Methods Dart Booleans Dart Type Conversion Dart Null Safety Dart late Dart Operators Dart Arithmetic Dart Assignment Dart Comparison Dart Logical Dart Type Test Dart Null Operators Dart Cascade Dart If...Else Dart Switch Dart While Loop Dart For Loop Dart Break/Continue

Dart Collections

Dart Lists Dart Access List Items Dart Change List Items Dart Loop Lists Dart List Methods Dart Sets Dart Maps Dart Access Map Items Dart Loop Maps Dart Collection if/for Dart Spread Operator

Dart Functions

Dart Functions Dart Parameters Dart Named Parameters Dart Return Values Dart Arrow Functions Dart Anonymous Functions Dart Closures Dart Scope Dart Recursion

Dart Classes

Dart OOP Dart Classes/Objects Dart Constructors Dart Named Constructors Dart Factory Constructors Dart Getters and Setters Dart Static Members Dart Inheritance Dart Abstract Classes Dart Interfaces Dart Mixins Dart Extension Methods Dart Enums Dart Generics

Dart 3 Features

Dart Records Dart Patterns Dart Switch Expressions Dart Sealed Classes Dart Class Modifiers

Dart Errors

Dart Exceptions Dart Custom Exceptions

Dart Async

Dart Async Intro Dart Futures Dart async/await Dart Streams Dart Isolates

Dart Libraries

Dart Imports Dart Packages Dart Math Dart Dates Dart JSON Dart RegExp Dart User Input Dart Files Dart Testing

Dart Examples

Dart Examples Dart Exercises


Dart Arithmetic Operators


Share

Dart Arithmetic Operators

Arithmetic operators are used to do common math with numbers.

OperatorNameDescriptionExample
+AdditionAdds two valuesx + y
-SubtractionSubtracts one value from anotherx - y
*MultiplicationMultiplies two valuesx * y
/DivisionDivides one value by another, the result is a doublex / y
~/Integer divisionDivides and removes the decimals, the result is an intx ~/ y
%ModulusGives the remainder of a divisionx % y
-NegationChanges the sign of a value-x
++IncrementAdds 1 to a variablex++
--DecrementSubtracts 1 from a variablex--

Example

void main() {
  int x = 10;
  int y = 3;

  print(x + y);
  print(x - y);
  print(x * y);
  print(-x);
}
Try it Yourself »

Result:

13
7
30
-10

Division

The / operator always gives a double, even when both numbers are integers:

Example

void main() {
  print(10 / 2);
  print(10 / 4);
}
Try it Yourself »

Result:

5.0
2.5

The ~/ operator divides and removes the decimals.

The result is an int:

Example

void main() {
  int cookies = 17;
  int children = 5;

  print(cookies ~/ children);
}
Try it Yourself »

Result:

3

Each child gets 3 cookies.



Modulus

The % operator gives the remainder, which is what is left over after a division:

Example

void main() {
  int cookies = 17;
  int children = 5;

  print(cookies % children);
}
Try it Yourself »

Result:

2

2 cookies are left over.

The modulus is often used to check if a number is even or odd.

An even number has a remainder of 0 when you divide it by 2:

Example

void main() {
  print(8 % 2);
  print(7 % 2);
}
Try it Yourself »

Result:

0
1

Mixing int and double

If one of the operands is a double, the result is also a double:

Example

void main() {
  int items = 3;
  double price = 2.5;

  print(items * price);
  print(items + 1.0);
}
Try it Yourself »

Result:

7.5
4.0

Increment and Decrement

The ++ operator adds 1 to a variable, and the -- operator subtracts 1:

Example

void main() {
  int likes = 10;

  likes++;
  print(likes);

  likes--;
  likes--;
  print(likes);
}
Try it Yourself »

Result:

11
9

You can write ++ before or after the variable.

The difference matters when you use the result in the same expression:

  • x++ gives the old value, then adds 1
  • ++x adds 1, then gives the new value

Example

void main() {
  int x = 5;
  print(x++);
  print(x);

  int y = 5;
  print(++y);
  print(y);
}
Try it Yourself »

Result:

5
6
6
6


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.