checkForCouldBeWholeNumber method

void checkForCouldBeWholeNumber()

Implementation

void checkForCouldBeWholeNumber() {
  // Whole numbers have implied infinite precision, but we need to check for digit errors in the last couple of digits
  if (precision > 17 && digits.length > 3) {
    int i = digits.length - 2;
    final String ch = digits[i]; // Second last character
    if (ch == '9') {
      while (i > 0 && digits[i - 1] == '9') {
        i--;
      }
      if (i > 0 && i < digits.length - 3) {
        digits = digits.substring(0, i - 1) +
            String.fromCharCode(digits.codeUnitAt(i - 1) + 1);
        precision = digits.length;
      }
    } else if (ch == '0') {
      while (i > 0 && digits[i - 1] == '0') {
        i--;
      }
      if (i > 0 && i < digits.length - 3) {
        digits = digits.substring(0, i);
        precision = digits.length;
      }
    }
  }
}