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,
- We define an integer
numwith a value of10. - We call the
toDoublemethod onnum. - 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,
- We define a BigInt
numwith a value of100. - We call the
toDoublemethod onnum. - 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.