formatCurrency method

String? formatCurrency(
  1. String isoCurrencyCode, {
  2. bool displayCurrency = true,
  3. String locale = 'en_US',
})

Implementation

String? formatCurrency(
  String isoCurrencyCode, {
  bool displayCurrency = true,
  String locale = 'en_US',
}) {
  try {
    if (this.isEmpty) return '0.00';

    var formatter = displayCurrency
        ? NumberFormat('${isoCurrencyCode}###,##0.00', locale)
        : NumberFormat('###,##0.00', locale);

    var formatValue = double.parse(this);
    var formattedText = formatter.format(formatValue / 100);

    return formattedText;
  } catch (e) {
    logger.error('tools.textformatter', 'Error formatting currency: $e');
  }

  return this;
}