How to Convert Currency to Words using Humanizer

1.5k Views Asked by At

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

2

There are 2 best solutions below

0
On

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

0
On

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