parse static method

Decimal parse(
  1. String source
)

Parses source as a decimal literal and returns its value as Decimal.

Implementation

static Decimal parse(String source) {
  final match = _pattern.firstMatch(source);
  if (match == null) {
    throw FormatException('$source is not a valid format');
  }
  final group1 = match.group(1);
  final group2 = match.group(2) ?? '';
  final group3 = match.group(3);

  var value = BigInt.parse('$group1$group2');
  var scale = group3 == null ? 0 : -int.parse(group3);
  scale += group2.length;
  return Decimal._(value, scale);
}