import 'package:intl/intl.dart';

extension NumExtension on num {
  String money([CurrencyUnit currency = CurrencyUnit.vnd]) {
    final int maximumFractionDigits =
    (currency == CurrencyUnit.vnd) ? 0 : 2;
    return "${numberFraction(maximumFractionDigits)}${currency.symbol}";
  }

  String numberFraction(int maxFractionDigits) {
    final formatter = NumberFormat.decimalPattern('vi_VN')
      ..maximumFractionDigits = maxFractionDigits
      ..minimumFractionDigits = 0;
    return formatter.format(this);
  }
}

enum CurrencyUnit {
  vnd(' đ'),
  usd(' USD'),
  eur(' EUR'),
  none(' '),
  point(' điểm');

  final String symbol;
  const CurrencyUnit(this.symbol);
}