toStandardNotation method

String toStandardNotation()

Returns the string representation of this value in standard notation.

@return the string representation in standard notation

Implementation

String toStandardNotation() {
  String? specialStr = getSpecialNumberString();
  if (specialStr != null) return specialStr;

  List<int> magnitude = List.filled(1, 0);

  String sigDigits = extractSignificantDigits(true, magnitude);
  int decimalPointPos = magnitude[0] + 1;

  String num = sigDigits;
// add a leading 0 if the decimal point is the first char
  if (sigDigits[0] == '.') {
    num = "0" + sigDigits;
  } else if (decimalPointPos < 0) {
    num = "0." + stringOfChar('0', -decimalPointPos) + sigDigits;
  } else if (sigDigits.indexOf('.') == -1) {
// no point inserted - sig digits must be smaller than magnitude of number
// add zeroes to end to make number the correct size
    int numZeroes = decimalPointPos - sigDigits.length;
    String zeroes = stringOfChar('0', numZeroes);
    num = sigDigits + zeroes + ".0";
  }

  if (this.isNegative()) return "-" + num;
  return num;
}