The `toDouble` method in Dart converts this number to a double.
The syntax of int.toDouble() method is:
double toDouble()
This toDouble() method of int return this num as a double.
int.toDouble() returns value of type double
.
In this example,
5
to the integer variable num
.num
to a double using the toDouble()
method.void main() {
int num = 5;
double doubleNum = num.toDouble();
print('Double value of $num: $doubleNum');
}
Double value of 5: 5
In this example,
-3
to the integer variable num
.num
to a double using the toDouble()
method.void main() {
int num = -3;
double doubleNum = num.toDouble();
print('Double value of $num: $doubleNum');
}
Double value of -3: -3
In this example,
10
to the integer variable num
.num
to a double using the toDouble()
method.void main() {
int num = 10;
double doubleNum = num.toDouble();
print('Double value of $num: $doubleNum');
}
Double value of 10: 10
In this Dart tutorial, we learned about toDouble() method of int: the syntax and few working examples with output and detailed explanation for each example.