Untitled

 avatar
unknown
plain_text
5 months ago
2.0 kB
4
Indexable
@override
PriceFormatterHook getPriceFormatterHook() {
    PriceFormatterHook priceFormatterHook = (String propertyPrice, String firstPrice) {
        try {
            // Convert the property price to a double
            double price = Double.parseDouble(propertyPrice);

            // Handle crores
            if (price >= 1_00_00_000) {
                return String.format("%.2f Cr", price / 1_00_00_000);
            }
            // Handle lakhs
            else if (price >= 1_00_000) {
                return String.format("%.2f L", price / 1_00_000);
            }
            // Handle thousands
            else if (price >= 1_000) {
                return String.format("%.2f K", price / 1_000);
            }
            // If it's less than a thousand, just return the price as is
            else {
                return String.format("%.2f", price);
            }
        } catch (NumberFormatException e) {
            // Handle invalid price input
            return propertyPrice;
        }
    };

    return priceFormatterHook;
}


@override
PriceFormatterHook getPriceFormatterHook() {
  PriceFormatterHook priceFormatterHook = (String propertyPrice, String firstPrice) {
    try {
      // Convert the property price to a double
      double price = double.parse(propertyPrice);

      // Handle crores
      if (price >= 10000000) {
        return (price / 10000000).toStringAsFixed(2) + " Cr";
      }
      // Handle lakhs
      else if (price >= 100000) {
        return (price / 100000).toStringAsFixed(2) + " L";
      }
      // Handle thousands
      else if (price >= 1000) {
        return (price / 1000).toStringAsFixed(2) + " K";
      }
      // If it's less than a thousand, just return the price as is
      else {
        return price.toStringAsFixed(2);
      }
    } catch (e) {
      // Handle invalid price input
      return propertyPrice;
    }
  };

  return priceFormatterHook;
}
Editor is loading...
Leave a Comment