extractSignificand static method

Decimal extractSignificand(
  1. String valueString
)

Implementation

static Decimal extractSignificand(String valueString) {
  var buffer = StringBuffer();
  var zeroBuffer = StringBuffer();
  for (var idx = 0; idx < valueString.length; idx++) {
    if (valueString[idx] == '.' ||
        valueString[idx] == '-' ||
        valueString[idx] == '+') {
      continue;
    }
    if (valueString[idx] == '0') {
      if (buffer.isEmpty) {
        continue;
      }
      zeroBuffer.write('0');
      continue;
    }

    if (zeroBuffer.isNotEmpty) {
      buffer.write(zeroBuffer);
      zeroBuffer.clear();
    }
    buffer.write(valueString[idx]);
  }
  return Decimal.parse('$buffer');
}