Files
Handwerks_app/services/german_amount_parser.dart
JUSN 9ddce354c0 Feature
ein paar feature aber datenbank macht probleme wenn man aufträge speichern möchge
2026-04-05 12:47:57 +02:00

30 lines
952 B
Dart
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// 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)}';
}
}