toSciNotation method
Returns the string representation of this value in scientific notation.
@return the string representation in scientific notation
Implementation
String toSciNotation() {
// special case zero, to allow as
if (isZero()) return SCI_NOT_ZERO;
String? specialStr = getSpecialNumberString();
if (specialStr != null) return specialStr;
List<int> magnitudeList = List.filled(1, 0);
String digits = extractSignificantDigits(false, magnitudeList);
String expStr = "$SCI_NOT_EXPONENT_CHAR${magnitudeList[0]}";
// should never have leading zeroes
// MD - is this correct? Or should we simply strip them if they are present?
if (digits[0] == '0') {
throw ArgumentError("Found leading zero: $digits");
}
// add decimal point
String trailingDigits = "";
if (digits.length > 1) trailingDigits = digits.substring(1);
String digitsWithDecimal = digits[0] + "." + trailingDigits;
if (this.isNegative()) return "-" + digitsWithDecimal + expStr;
return digitsWithDecimal + expStr;
}