Dart double toDouble()
Syntax & Examples


double.toDouble() method

The `toDouble` method converts the given number to a double.


Syntax of double.toDouble()

The syntax of double.toDouble() method is:

 double toDouble() 

This toDouble() method of double return this num as a double.

Return Type

double.toDouble() returns value of type double.



✐ Examples

1 Convert an integer to a double

In this example,

  1. We define an integer num with a value of 10.
  2. We call the toDouble method on num.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 10;
  double result = num.toDouble();
  print('Result: $result');
}

Output

Result: 10

2 Convert a BigInt to a double

In this example,

  1. We define a BigInt num with a value of 100.
  2. We call the toDouble method on num.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(100);
  double result = num.toDouble();
  print('Result: $result');
}

Output

Result: 100

Summary

In this Dart tutorial, we learned about toDouble() method of double: the syntax and few working examples with output and detailed explanation for each example.