Menu
Coddy logo textTech

Doubles (double)

Part of the Fundamentals section of Coddy's Dart journey — lesson 8 of 94.

Doubles (double type) are numbers with decimal points for precise values.

void main() {
  double price = 19.99;
  print(price);
}

Doubles can be used in calculations:

void main() {
  double temperature = 72.5;
  print(temperature);
  
  // Increase the temperature
  temperature = 75.8;
  print(temperature);
  
  // Create another double
  double increase = 2.5;
  
  // Combine doubles
  double newTemperature = temperature + increase;
  print(newTemperature);
}
challenge icon

Challenge

Beginner

Create a program that works with double values (decimal numbers) in Dart:

  1. Declare a double variable named temperature with a value of 98.6
  2. Declare a double variable named weight with a value of 7.5
  3. Print both variables with descriptive labels

Your output should match the expected format exactly:
Temperature: temperature 

Weight: weight 

Cheat sheet

The double type stores numbers with decimal points:

double price = 19.99;

Doubles can be used in calculations and reassigned:

double temperature = 72.5;
temperature = 75.8;  // Reassign value

double increase = 2.5;
double newTemperature = temperature + increase;  // Combine doubles

Try it yourself

void main() {
  // Declare your double variables here
  double temperature = ?;
  double weight = ?;
  
  // Print the variables with labels
  print("Temperature: " + temperature.toString());
  print("Weight: " + weight.toString());
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals