rabattCents function

int? rabattCents(
  1. RabattArt art,
  2. num wert,
  3. int summe
)

Rabatt in Cent aus der Eingabe; außerhalb von 0 … Summe gibt es keinen.

Implementation

int? rabattCents(RabattArt art, num wert, int summe) {
  if (wert.isNaN || wert.isInfinite || wert < 0) return null;
  if (art == RabattArt.prozent && wert > 100) return null;
  final c = art == RabattArt.prozent ? (summe * wert / 100).round() : wert.round();
  if (c > summe) return null;
  return c;
}