Dart .toDouble()

Anonymous contributor's avatar
Anonymous contributor
Published May 20, 2024
Contribute to Docs

In Dart, the .toDouble() method is used to convert numeric data types, such as int, to their corresponding double-precision floating-point representation.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours

Syntax

numericValue.toDouble();
  • numericValue: Represents the variable to be converted to double.

Example

The following example demonstrates how to use the .toDouble() method to convert an integer to a double:

void main() {
int number = 3;
double value = number.toDouble();
print("Output = ${value}");
}

The above code produces the following output:

Output = 3.0

Note: The output 3.0 is a double. This can be confirmed by checking value.runtimeType.

All contributors

Contribute to Docs

Learn Dart on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours