Dart BigInt toString()
Syntax & Examples


BigInt.toString() method

The `toString` method of BigInt class in Dart converts an integer to its string representation.


Syntax of BigInt.toString()

The syntax of BigInt.toString() method is:

 String toString() 

This toString() method of BigInt returns a String-representation of this integer.

Return Type

BigInt.toString() returns value of type String.



✐ Examples

1 Convert BigInt to String

In this example,

  1. We create a BigInt object, num, initialized with an integer.
  2. We use the toString method to convert the BigInt to its string representation.
  3. We print the string representation to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(12345);
  String str = num.toString();
  print('BigInt to string: $str');
}

Output

BigInt to string: 12345

2 Convert Negative BigInt to String

In this example,

  1. We create a BigInt object, num, initialized with a negative integer.
  2. We use the toString method to convert the BigInt to its string representation.
  3. We print the string representation to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(-98765);
  String str = num.toString();
  print('BigInt to string: $str');
}

Output

BigInt to string: -98765

3 Convert Zero BigInt to String

In this example,

  1. We create a BigInt object, num, initialized with zero.
  2. We use the toString method to convert the BigInt to its string representation.
  3. We print the string representation to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(0);
  String str = num.toString();
  print('BigInt to string: $str');
}

Output

BigInt to string: 0

Summary

In this Dart tutorial, we learned about toString() method of BigInt: the syntax and few working examples with output and detailed explanation for each example.