CodeBlanks Logo Icon CodeBlanks

Floating-point types

Learn double and floating-point numbers.

The double type

Decimal numbers in Dart are stored in the double type. A double is a 64-bit IEEE 754 floating-point number.

Example: double price = 19.99;. Decimals suit real values like money, temperature, measurements.

In Dart the division operator / always returns a double. So 5 / 2 gives 2.5, not 2. For integer division you use ~/ (we will see it later).

Scientific notation

You can write very large or very small decimals using scientific notation. For example 1e3 is 1000.0; 3.14E-2 is 0.0314.

The letter e or E means 'times 10 to the power of'. The number after it is the exponent. This form is common in physics and engineering.

The result is still a double. So var x = 1e3; makes x a double, not an int.

Practice double variable

Declare double price = 19.99; and print it with print(price);.

Starter code

main.dart
// Declare a double variable

Sample solution

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

Expected output

19.99

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the result of 5 / 2 in Dart?

main.dart
5 / 2
  • 2.5 Correct answer
  • 2
  • Throws an error
  • 3

Explanation: / always returns a double.

2 Floating-point type

Question
____ price = 9.99;
Answer
double price = 9.99;

Explanation: double is for decimal numbers.

3 Decimal concepts

Term Meaning
double Floating-point
int Integer
1e3 Scientific
/ Division (double)

All lessons in Beginner