getDigits static method

Digits? getDigits(
  1. FormatStyle style,
  2. Digits? digits
)

Implementation

static Digits? getDigits(FormatStyle style, Digits? digits) {
  final fractionDigits = digits?.fractionDigits;
  if (fractionDigits != null) {
    final int newMin;
    if (fractionDigits.$1 == null) {
      newMin = switch (style) {
        DecimalStyle() => 0,
        // TODO(mosum): get by ISO 4217 currency code list instead
        CurrencyStyle() => 2,
        PercentStyle() => 0,
        UnitStyle() => 0,
      };
    } else {
      newMin = fractionDigits.$1!;
    }
    final int newMax;
    if (fractionDigits.$2 == null) {
      newMax = switch (style) {
        DecimalStyle() => max(newMin, 3),
        // TODO(mosum): get by ISO 4217 currency code list instead
        CurrencyStyle() => max(newMin, 2),
        PercentStyle() => max(newMin, 0),
        UnitStyle() => max(newMin, 3),
      };
    } else {
      newMax = fractionDigits.$2!;
    }
    return Digits._(
      roundingIncrement: digits!.roundingIncrement,
      fractionDigits: (newMin, newMax),
      roundingPriority: digits.roundingPriority,
      significantDigits: digits.significantDigits,
    );
  }
  return digits;
}