pCurrencyFormat function

Object pCurrencyFormat(
  1. dynamic value, {
  2. String? locale,
  3. String? symbol,
  4. int? decimalDigits,
  5. bool? isCurrencyCompact,
})

Implementation

Object pCurrencyFormat(
    dynamic value, {
      String? locale,
      String? symbol,
      int? decimalDigits,
      bool? isCurrencyCompact,
    }) {
  try {
    if (value == null || value == '') {
      value = 0;
    }
    double price = double.parse((value).toString());
    if (isCurrencyCompact ?? false) {
      return NumberFormat.compactCurrency(
        locale: locale,
        symbol: symbol,
        decimalDigits: decimalDigits,
      ).format(price);
    } else {
      return NumberFormat.currency(
        locale: locale,
        symbol: symbol,
        decimalDigits: decimalDigits,
      ).format(price);
    }
  } catch (e) {
    pShowToast(message: 'You Enter Invalid Amount');
    return 0;
  }
}