nepali_utils icon indicating copy to clipboard operation
nepali_utils copied to clipboard

Nepali currency in words

Open roopaish opened this issue 1 year ago • 0 comments

Instead of

print('123456 -> ${inWords.format(123456)}');
// 123456 -> 1 lakh 23 thousand 4 hundred 56

Can we have

print('123456 -> ${inWords.format(123456)}');
// 123456 -> one lakh twenty three thousand four hundred fifty six

I didn't find a way in this library to do this.

I ended up using this package with intl package like this

String amountToNepaliWords(double value) {
  // Format the number to Nepali words
  NepaliNumberFormat nepaliNumberFormat = NepaliNumberFormat(
    inWords: true,
    decimalDigits: 2,
    isMonetory: true,
    includeDecimalIfZero: false,
  );

  String formattedAmount = nepaliNumberFormat.format(value);

  // Convert formatted number to letters
  String amountInLetters = formattedAmount.replaceAllMapped(
    RegExp(r'\d+'),
    (match) => NumberToWordsEnglish.convert(int.parse(match.group(0)!)),
  );

  return amountInLetters;
}

roopaish avatar Jul 27 '23 07:07 roopaish