Dart double toStringAsExponential()
Syntax & Examples
double.toStringAsExponential() method
Returns an exponential string-representation of the given numeric value with optional fraction digits.
Syntax of double.toStringAsExponential()
The syntax of double.toStringAsExponential() method is:
String toStringAsExponential([int fractionDigits ])
This toStringAsExponential() method of double returns an exponential string-representation of this
.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
fractionDigits | optional | the number of digits after the decimal point |
Return Type
double.toStringAsExponential() returns value of type String
.
✐ Examples
1 Example with default fraction digits
In this example,
- We create a numeric value
numValue
with the value 12345.6789. - We then use the
toStringAsExponential()
method without specifying the fraction digits, which defaults to the default number of digits. - We print the exponential string representation to standard output.
Dart Program
void main() {
num numValue = 12345.6789;
String exponentialStr = numValue.toStringAsExponential();
print(exponentialStr);
}
Output
1.23456789e+4
2 Example with 2 fraction digits
In this example,
- We create a numeric value
numValue
with the value 12345.6789. - We then use the
toStringAsExponential()
method with 2 fraction digits specified. - We print the exponential string representation to standard output.
Dart Program
void main() {
num numValue = 12345.6789;
String exponentialStr = numValue.toStringAsExponential(2);
print(exponentialStr);
}
Output
1.23e+4
3 Example with 4 fraction digits
In this example,
- We create a numeric value
numValue
with the value 12345.6789. - We then use the
toStringAsExponential()
method with 4 fraction digits specified. - We print the exponential string representation to standard output.
Dart Program
void main() {
num numValue = 12345.6789;
String exponentialStr = numValue.toStringAsExponential(4);
print(exponentialStr);
}
Output
1.2346e+4
Summary
In this Dart tutorial, we learned about toStringAsExponential() method of double: the syntax and few working examples with output and detailed explanation for each example.