parsePrice static method

String parsePrice(
  1. dynamic p
)

Implementation

static String parsePrice(p) {
  String? stringedPrice;
  if (p is double) {
    stringedPrice = "$p";
  } else {
    stringedPrice = p;
  }

  if (stringedPrice != null && double.tryParse(stringedPrice) != null) {
    double price = double.parse(stringedPrice);
    if (price % 1 == 0) {
      return NumberFormat.currency(locale: 'es_ES', symbol: '', decimalDigits: 0).format(price.round());
    }
    return NumberFormat.currency(locale: 'es_ES', symbol: '', decimalDigits: 2).format(price);
  }
  return "0";
}