AmountConverter constructor

AmountConverter({
  1. required int decimals,
  2. int? displayPrecision = 8,
})

Creates a converter with the specified decimals and displayPrecision.

Throws AmountConverterException if:

  • decimals is negative or exceeds BinaryOps.mask8.
  • displayPrecision is negative.

Implementation

factory AmountConverter({required int decimals, int? displayPrecision = 8}) {
  if (decimals.isNegative || decimals > BinaryOps.mask8) {
    throw AmountConverterException(
      'Invalid decimals value: must be between 0 and ${BinaryOps.mask8}.',
    );
  }
  if (displayPrecision != null && displayPrecision.isNegative) {
    throw AmountConverterException(
      "Invalid displayPrecision value: must be non-negative.",
    );
  }
  return AmountConverter._(
    decimals: decimals,
    displayPrecision: displayPrecision,
  );
}