int vs double and Integer Division
Mix number types and use the tilde-slash operator.
Two Number Types
Dart has two number types: int for whole numbers and double for decimals. Both descend from num, so they mix in math. 🔢
void main() {
int age = 30;
double price = 4.99;
}int Holds Whole Numbers
An int stores values with no fractional part, like counts and indexes. Writing 5 with no dot makes it an int automatically.
void main() {
int count = 5;
print(count); // 5
}All lessons in this course
- Arithmetic and Operator Precedence
- int vs double and Integer Division
- Parsing and Converting Numbers
- The dart:math Toolkit