Dart int toStringAsExponential()
Syntax & Examples


int.toStringAsExponential() method

The `toStringAsExponential` method in Dart returns an exponential string representation of this number.


Syntax of int.toStringAsExponential()

The syntax of int.toStringAsExponential() method is:

 String toStringAsExponential([int fractionDigits ]) 

This toStringAsExponential() method of int returns an exponential string-representation of this.

Parameters

ParameterOptional/RequiredDescription
fractionDigitsoptionalThe number of digits after the decimal point.

Return Type

int.toStringAsExponential() returns value of type String.



✐ Examples

1 Exponential representation with default fraction digits

In this example,

  1. We assign the value 123456789 to the integer variable num.
  2. We convert num to an exponential string using the toStringAsExponential() method.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 123456789;
  String exponentialString = num.toStringAsExponential();
  print('Exponential representation of $num: $exponentialString');
}

Output

Exponential representation of 123456789: 1.23456789e+8

2 Exponential representation with custom fraction digits

In this example,

  1. We assign the value 123456789 to the integer variable num.
  2. We convert num to an exponential string with 2 fraction digits using the toStringAsExponential() method.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 123456789;
  String exponentialString = num.toStringAsExponential(2);
  print('Exponential representation of $num with 2 fraction digits: $exponentialString');
}

Output

Exponential representation of 123456789 with 2 fraction digits: 1.23e+8

3 Exponential representation with custom fraction digits

In this example,

  1. We assign the value 987654321 to the integer variable num.
  2. We convert num to an exponential string with 4 fraction digits using the toStringAsExponential() method.
  3. We print the result to standard output.

Dart Program

void main() {
  int num = 987654321;
  String exponentialString = num.toStringAsExponential(4);
  print('Exponential representation of $num with 4 fraction digits: $exponentialString');
}

Output

Exponential representation of 987654321 with 4 fraction digits: 9.8765e+8

Summary

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