amountWithCurrency static method

String amountWithCurrency(
  1. String? symbolData,
  2. double? amount, {
  3. bool isShowCurrencyOnly = false,
})

Implementation

static String amountWithCurrency(
  String? symbolData,
  double? amount, {
  bool isShowCurrencyOnly = false,
}) {
  String symbol = "";
  switch (symbolData) {
    case "Rupee":
      symbol = "₹";
      break;
    case "USD":
      symbol = "\$";
      break;
    case "KHR":
      symbol = "៛";
      break;
    default:
      symbol = "₹"; // Default to Rupee if symbolData is null or invalid
      break;
  }
  if (isShowCurrencyOnly) {
    return symbol;
  } else if (amount == null || amount == 0) {
    return "$symbol${amount?.toInt()}"; // Display as integer if amount is zero or null
  } else {
    // Round to two decimal places for non-zero amounts
    String formattedAmount = amount.toStringAsFixed(2);
    // Remove trailing zeros and decimal point if necessary
    formattedAmount = formattedAmount.replaceAll(RegExp(r"(\.0*)?$"), "");
    return "$symbol$formattedAmount";
  }
}