Dart .toStringAsExponential()
Published Jun 12, 2024
Contribute to Docs
The .toStringAsExponential() method in Dart is used for type conversion, converting a number to exponential notation and then converting it to a string format. It can be applied to both integers and doubles.
Syntax
number.toStringAsExponential([int fractionDigits])
number: This refers to a numeric value, either an integer or a double, on which the.toStringAsExponential()method is called.fractionDigits: An integer ranging from 0 to 20 indicating the digits after the decimal point. If not specified, it defaults to as many digits as needed for accuracy.
Example
The example below shows the usage of .toStringAsExponential() method:
void main() {double number = 23625.585;String result1 = number.toStringAsExponential();String result2 = number.toStringAsExponential(5);print("Without fraction digits: ${result1}");print("With fraction digits: ${result2}");}
This Dart example uses .toStringAsExponential() on a double to show both default and customized exponential notation with 5 fraction digits specified. This generates the following output:
Without fraction digits: 2.3625585e+4With fraction digits: 2.36256e+4
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Dart on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours