cToCurrency method

String cToCurrency({
  1. dynamic removePointValueIfEmpty = true,
  2. dynamic symbol = '₹ ',
  3. dynamic currencyFormat = 'HI',
  4. dynamic decimalDigits = 2,
})

Converts a number string to a custom currency format.

Implementation

String cToCurrency({
  removePointValueIfEmpty = true,
  symbol = '₹ ',
  currencyFormat = 'HI',
  decimalDigits = 2,
}) {
  var emptyPoint = '.' +
      cBuildString(
        (sb) {
          for (var i = 0; i < decimalDigits; i++) {
            sb.write('0');
          }
        },
      );
  var value = NumberFormat.currency(
    symbol: symbol,
    locale: currencyFormat,
    decimalDigits: decimalDigits,
  ).format(double.parse(this));
  return (removePointValueIfEmpty) ? value.replaceAll(emptyPoint, '') : value;
}