Dart BigInt.from()
Syntax & Examples
BigInt.from constructor
The `BigInt.from()` constructor allocates a big integer from the provided numeric value.
Syntax of BigInt.from
The syntax of BigInt.BigInt.from constructor is:
BigInt.from(num value)
This BigInt.from constructor of BigInt allocates a big integer from the provided value
number.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
value | required | the number to create a BigInt from |
✐ Examples
1 BigInt from number
In this example,
- We declare a variable
number
with a value of123456789
. - We use the
BigInt.from()
constructor to create aBigInt
from thenumber
. - We print the resulting
BigInt
.
Dart Program
void main() {
num number = 123456789;
BigInt bigIntFromNumber = BigInt.from(number);
print('BigInt from number: $bigIntFromNumber');
}
Output
BigInt from number: 123456789
2 BigInt from char
In this example,
- We declare a variable
char
with a value of'A'
. - We use the
BigInt.from()
constructor to create aBigInt
from the character code of'A'
. - We print the resulting
BigInt
.
Dart Program
void main() {
String char = 'A';
BigInt bigIntFromChar = BigInt.from(char.codeUnitAt(0));
print('BigInt from char: $bigIntFromChar');
}
Output
BigInt from char: 65
Summary
In this Dart tutorial, we learned about BigInt.from constructor of BigInt: the syntax and few working examples with output and detailed explanation for each example.