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