DecimalCodec constructor
DecimalCodec({})
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.',
);
}
}