DecimalCodec constructor

DecimalCodec({
  1. bool grouping = true,
  2. String groupSeparator = ',',
  3. String decimalSeparator = '.',
  4. int minFractionDigits = 0,
  5. int maxFractionDigits = 3,
  6. bool trimTrailingZeros = true,
  7. Rounding rounding = Rounding.halfUp,
})

Creates a codec for ordinary decimal numbers.

Implementation

DecimalCodec({
  this.grouping = true,
  this.groupSeparator = ',',
  this.decimalSeparator = '.',
  this.minFractionDigits = 0,
  this.maxFractionDigits = 3,
  this.trimTrailingZeros = true,
  this.rounding = Rounding.halfUp,
}) {
  checkFractionDigits(minFractionDigits, maxFractionDigits);
  checkNotEmpty(decimalSeparator, 'decimalSeparator');
  _checkSeparator(decimalSeparator, 'decimalSeparator');
  if (grouping) {
    checkNotEmpty(groupSeparator, 'groupSeparator');
    _checkSeparator(groupSeparator, 'groupSeparator');
  }
  if (grouping && groupSeparator == decimalSeparator) {
    throw ArgumentError.value(
      groupSeparator,
      'groupSeparator',
      'Must differ from decimalSeparator.',
    );
  }
  if (grouping &&
      (groupSeparator.contains(decimalSeparator) ||
          decimalSeparator.contains(groupSeparator))) {
    throw ArgumentError.value(
      groupSeparator,
      'groupSeparator',
      'Must not overlap with decimalSeparator.',
    );
  }
}