asExponential method
String
asExponential(
- int precision, {
- bool removeTrailingZeros = true,
})
Implementation
String asExponential(int precision, {bool removeTrailingZeros = true}) {
int offset = _decimal - _exponent;
int extraZeroes = precision - (_digits.length - offset) + 1;
if (extraZeroes > 0) {
_digits.addAll(
Formatter.getPadding(extraZeroes, '0').split('').map(int.parse));
}
_round(offset + precision, offset);
String ret = _digits[offset - 1].toString();
List<int> trailingDigits = _digits.sublist(offset, offset + precision);
String _expStr = _exponent.abs().toString();
if (_exponent < 10 && _exponent > -10) {
_expStr = "0$_expStr";
}
_expStr = (_exponent < 0) ? "e-$_expStr" : "e+$_expStr";
if (removeTrailingZeros) {
trailingDigits = _removeTrailingZeros(trailingDigits);
}
if (trailingDigits.length > 0) {
ret += '.';
}
ret = trailingDigits.fold(ret, (i, e) => "$i$e");
ret = "$ret$_expStr";
return ret;
}