FdcDecimal.parse constructor

FdcDecimal.parse(
  1. String text, {
  2. int? scale,
  3. String decimalSeparator = '.',
  4. String? thousandSeparator,
  5. bool negative = true,
  6. bool allowCommaDecimalFallback = true,
})

Parses decimal text.

When scale is omitted, the scale is inferred from the parsed text. Pass scale to round and normalize the value to a fixed number of decimals.

Implementation

factory FdcDecimal.parse(
  String text, {
  int? scale,
  String decimalSeparator = '.',
  String? thousandSeparator,
  bool negative = true,
  bool allowCommaDecimalFallback = true,
}) {
  final decimal = tryParse(
    text,
    scale: scale,
    decimalSeparator: decimalSeparator,
    thousandSeparator: thousandSeparator,
    negative: negative,
    allowCommaDecimalFallback: allowCommaDecimalFallback,
  );
  if (decimal == null) {
    throw FormatException('Invalid decimal value.', text);
  }
  return decimal;
}