Mayur Chaudhary
Mayur Chaudhary

Reputation: 324

Convert number to scientific notation and obtain exponent flutter

How can I convert a number to scientific notation and obtain the exponent? For example if I have 0.000000001 and want to convert it to 1e-9

Upvotes: 2

Views: 1342

Answers (1)

dm_tr
dm_tr

Reputation: 4773

Use the intl package and try it as following

final value = 0.000000025;
String res = NumberFormat.scientificPattern(Localizations.localeOf(context).languageCode).format(value);
print("Formatted value is $res");

EDIT
A better and cleaner approach, which does not require any additional package, is the method toStringAsExponential(). Here is how to use it

final value = 0.000000025;
print(value.toStringAsExponential());

Upvotes: 2

Related Questions