01a0f1029f
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
1.0 KiB
Dart
29 lines
1.0 KiB
Dart
import 'package:intl/intl.dart';
|
|
|
|
final NumberFormat _euro = NumberFormat.currency(locale: 'fr_FR', symbol: '€');
|
|
final DateFormat _dateHeure = DateFormat('d MMM y • HH:mm', 'fr_FR');
|
|
|
|
String euro(double v) => _euro.format(v);
|
|
|
|
/// Formate un nombre de points de façon lisible :
|
|
/// entier sans décimale (« 12 pts »), sinon jusqu'à 2 décimales sans zéros
|
|
/// inutiles (« 0,48 pt », « 2,5 pts »). Gère le singulier/pluriel.
|
|
String points(double v) {
|
|
final arrondi = (v * 100).round() / 100;
|
|
var s = arrondi == arrondi.roundToDouble()
|
|
? arrondi.toInt().toString()
|
|
: arrondi
|
|
.toStringAsFixed(2)
|
|
.replaceAll(RegExp(r'0+$'), '')
|
|
.replaceAll(RegExp(r'\.$'), '');
|
|
s = s.replaceAll('.', ',');
|
|
final pluriel = arrondi.abs() >= 2 ? 'pts' : 'pt';
|
|
return '$s $pluriel';
|
|
}
|
|
|
|
/// Comme [points] mais sans le suffixe « pt/pts » (pour les gros affichages).
|
|
String pointsNombre(double v) =>
|
|
points(v).replaceAll(RegExp(r'\s?pts?$'), '');
|
|
|
|
String dateHeure(DateTime d) => _dateHeure.format(d);
|