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

ParameterOptional/RequiredDescription
valuerequiredthe number to create a BigInt from


✐ Examples

1 BigInt from number

In this example,

  1. We declare a variable number with a value of 123456789.
  2. We use the BigInt.from() constructor to create a BigInt from the number.
  3. 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,

  1. We declare a variable char with a value of 'A'.
  2. We use the BigInt.from() constructor to create a BigInt from the character code of 'A'.
  3. 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.