Dart num toStringAsExponential()
Syntax & Examples
num.toStringAsExponential() method
The `toStringAsExponential` method in Dart returns an exponential string representation of this number.
Syntax of num.toStringAsExponential()
The syntax of num.toStringAsExponential() method is:
 String toStringAsExponential([int fractionDigits ]) This toStringAsExponential() method of num returns an exponential string-representation of this.
Parameters
| Parameter | Optional/Required | Description | 
|---|---|---|
fractionDigits | optional | The number of digits after the decimal point. If not provided, it defaults to null. | 
Return Type
num.toStringAsExponential() returns value of type  String.
✐ Examples
1 Exponential representation without specifying fraction digits
In this example,
- We create a num variable 
num1with the value 123456.789. - We use the 
toStringAsExponential()method to get its exponential string representation. - We then print the result to standard output.
 
Dart Program
void main() {
  num num1 = 123456.789;
  String exponentialString = num1.toStringAsExponential();
  print('Exponential representation of $num1: $exponentialString');
}Output
Exponential representation of 123456.789: 1.23456789e+5
2 Exponential representation with 2 fraction digits
In this example,
- We create a num variable 
num1with the value 123456.789. - We use the 
toStringAsExponential()method with 2 fraction digits to get its exponential string representation. - We then print the result to standard output.
 
Dart Program
void main() {
  num num1 = 123456.789;
  String exponentialString = num1.toStringAsExponential(2);
  print('Exponential representation of $num1 with 2 fraction digits: $exponentialString');
}Output
Exponential representation of 123456.789 with 2 fraction digits: 1.23e+5
Summary
In this Dart tutorial, we learned about toStringAsExponential() method of num: the syntax and few working examples with output and detailed explanation for each example.