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
Parameter | Optional/Required | Description |
---|---|---|
fractionDigits | optional | The 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,
- We assign the value
123456789
to the integer variablenum
. - We convert
num
to an exponential string using thetoStringAsExponential()
method. - 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,
- We assign the value
123456789
to the integer variablenum
. - We convert
num
to an exponential string with 2 fraction digits using thetoStringAsExponential()
method. - 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,
- We assign the value
987654321
to the integer variablenum
. - We convert
num
to an exponential string with 4 fraction digits using thetoStringAsExponential()
method. - 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.