Dart BigInt toDouble()
Syntax & Examples
BigInt.toDouble() method
The `toDouble` method of BigInt class in Dart converts a BigInt to a double.
Syntax of BigInt.toDouble()
The syntax of BigInt.toDouble() method is:
double toDouble()
This toDouble() method of BigInt returns this BigInt as a double.
Return Type
BigInt.toDouble() returns value of type double
.
✐ Examples
1 Convert BigInt to Double
In this example,
- We create a BigInt object,
num
, initialized with a large integer. - We use the
toDouble
method to convert the BigInt to a double. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.parse('1234567895269666362');
double result = num.toDouble();
print('BigInt to double: $result');
}
Output
BigInt to double: 1234567895269666300
2 Convert Another BigInt to Double
In this example,
- We create a BigInt object,
num
, initialized with another large integer. - We use the
toDouble
method to convert the BigInt to a double. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(987654321);
double result = num.toDouble();
print('BigInt to double: $result');
}
Output
BigInt to double: 987654321
3 Convert Big Integer to Double
In this example,
- We create a BigInt object,
num
, initialized with a big integer. - We use the
toDouble
method to convert the BigInt to a double. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(1000000000);
double result = num.toDouble();
print('BigInt to double: $result');
}
Output
BigInt to double: 1000000000
Summary
In this Dart tutorial, we learned about toDouble() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.