Files
kooltab/lib/utils/money.dart
T
2026-10-19 21:41:34 +02:00

21 lines
659 B
Dart

import 'package:intl/intl.dart';
final _euro = NumberFormat.currency(locale: 'nl_BE', symbol: '€');
final _euroInput = RegExp(r'^(\d{1,6})(?:[.,](\d{1,2}))?$');
extension Cents on int {
String get asEuro => _euro.format(this / 100);
}
/// Parses a typed price like `2,50` or `3` without going through doubles.
/// Returns null for anything else, including more than two decimals.
int? parseEuroToCents(String input) {
final match = _euroInput.firstMatch(input.trim());
if (match == null) return null;
final euros = int.parse(match.group(1)!);
final cents = int.parse((match.group(2) ?? '0').padRight(2, '0'));
return euros * 100 + cents;
}