30 lines
952 B
Dart
30 lines
952 B
Dart
/// Parst typische deutsche Betragsangaben (z. B. `1.234,56`) für QR / Logik.
|
||
class GermanAmountParser {
|
||
GermanAmountParser._();
|
||
|
||
/// Liefert den Betrag in Euro als [double], oder `null` wenn nicht erkennbar.
|
||
static double? parseEuro(String raw) {
|
||
var s = raw.trim();
|
||
if (s.isEmpty) return null;
|
||
s = s.replaceAll(RegExp(r'\s'), '');
|
||
s = s.replaceAll('€', '').replaceAll('EUR', '').trim();
|
||
if (s.isEmpty) return null;
|
||
if (s.contains(',')) {
|
||
s = s.replaceAll('.', '').replaceAll(',', '.');
|
||
} else {
|
||
final dotCount = '.'.allMatches(s).length;
|
||
if (dotCount > 1) {
|
||
s = s.replaceAll('.', '');
|
||
}
|
||
}
|
||
return double.tryParse(s);
|
||
}
|
||
|
||
/// Betrag für SEPA-QR: `EUR12.34` (Punkt, zwei Nachkommastellen).
|
||
static String? formatForSepaQr(String betragText) {
|
||
final v = parseEuro(betragText);
|
||
if (v == null || v <= 0) return null;
|
||
return 'EUR${v.toStringAsFixed(2)}';
|
||
}
|
||
}
|