1

I need to use the Nuget package Humanizer to convert currency to English words equivalent as follows

 using Humanizer;

 AmountInWords = pmt.Amount.ToWords()

pmt.Amount is of type decimal and it represents the amount in figures

I get the following error

Error   CS1929  'decimal' does not contain a definition for 'ToWords' and the best extension method overload 'NumberToWordsExtension.ToWords(int, CultureInfo)' requires a receiver of type 'int'

I have checked the documentation at the following url and I am not yet able to find a way to resolve it

https://github.com/Humanizr/Humanizer#number-to-words

I will appreciate any guide to resolve this.

Thank you

Josh
  • 1,660
  • 5
  • 33
  • 55
  • https://github.com/Humanizr/Humanizer/blob/60822b6ddbfef1097feb873fd0161dc812576fce/src/Humanizer/NumberToWordsExtension.cs - you will have to use int or long – ASh Feb 09 '22 at 09:30
  • I guess you'll have to humanize full Currency and fractional Currency separately. So for example "$35,70" become "Thirtyfive Dollars and seventy Cents". – Fildor Feb 09 '22 at 10:00
  • That would mean having to split the figure and humanizing the two parts separately. That is actually what I am planning to do if no other solution comes up here. But I wish there could be a better way – Josh Feb 09 '22 at 11:01
  • Do you want such a conversion? https://stackoverflow.com/questions/43334034/convert-number-with-decimals-in-currency-to-words – Tupac Feb 25 '22 at 06:47

2 Answers2

1

As far as I can see Humanizer doesn't have a built in solution to this. I did come across this GitHub project that someone posted that you might look at. It seems the suggestion of splitting into two numbers is the right approach.

https://github.com/tiagonmas/ConvertCurrencyToText

Jules
  • 563
  • 1
  • 5
  • 16
-1

Since, 'decimal' format does not contain a definition for 'ToWords' so it requires a receiver of type 'int'. So convert it into 'Int' then Try.

    using Humanizer;
    
    AmountInWords = Convert.ToInt64(pmt.Amount).ToWords()

Thanks & Regards

Priyadharshini Charles