toPriceAmount method

String toPriceAmount({
  1. String? currencySymbol,
})

Tries to format the current String to price amount.

You can optionally pass the currencySymbol to append a symbol to the formatted text.

Example

String price = '1234567';
String formattedPrice = foo1.toPriceAmount(currencySymbol: '€'); // returns '12.345,67 €'

Implementation

String toPriceAmount({String? currencySymbol}) {
  if (this.isBlank) {
    return this;
  }

  try {
    var f = NumberFormat.currency(locale: 'el_GR');

    return f
        .format(double.tryParse(this.replaceAll(',', '.')))
        .replaceAll('EUR', '')
        .trim()
        .append(currencySymbol == null ? '' : ' $currencySymbol');
  } catch (e) {
    return '';
  }
}