Dart BigInt toInt()
Syntax & Examples
BigInt.toInt() method
The `toInt()` method of BigInt class returns this BigInt as an integer.
Syntax of BigInt.toInt()
The syntax of BigInt.toInt() method is:
int toInt()
This toInt() method of BigInt returns this BigInt as an int.
Return Type
BigInt.toInt() returns value of type int
.
✐ Examples
1 Convert a positive BigInt to int
In this example,
- We create a BigInt
bigInt
with a value of123456789
. - We use the
toInt()
method to convert it to an integer. - We print the converted value to standard output.
Dart Program
void main() {
BigInt bigInt = BigInt.from(123456789);
int intValue = bigInt.toInt();
print('Converted value to int: $intValue');
}
Output
Converted value to int: 123456789
2 Convert a negative BigInt to int
In this example,
- We create a BigInt
bigInt
with a value of-987654321
. - We use the
toInt()
method to convert it to an integer. - We print the converted value to standard output.
Dart Program
void main() {
BigInt bigInt = BigInt.from(-987654321);
int intValue = bigInt.toInt();
print('Converted value to int: $intValue');
}
Output
Converted value to int: -987654321
Summary
In this Dart tutorial, we learned about toInt() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.