如何将数字转换为科学记数法并获得指数?例如,如果我有 0.000000001 并想将其转换为 1e-9
最佳答案
使用 intl package并尝试如下
final value = 0.000000025;
String res = NumberFormat.scientificPattern(Localizations.localeOf(context).languageCode).format(value);
print("Formatted value is $res");
编辑 一种更好、更干净的方法,不需要任何额外的包,是方法 toStringAsExponential()
.这是如何使用它
final value = 0.000000025;
print(value.toStringAsExponential());