Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14215

Convert amount to word in Python In Indian Format

$
0
0

How to convert amount to word in Indian?

I was using num2words library but its is presenting wrong set of words while presenting 'lakhs' and 'crores'.

For example:

num2words(903614.55, lang='en-IN')Its printing 'nine hundred and three thousand, six hundred and fourteen point five five'

But actual Indian Amount Presentation should be nine lakhs three thousand six hundred fourteen and five five paisa.

Then I tried the below code:

def num2words(num):    under_20 = ['Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Eleven','Twelve','Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen']    tens = ['Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety']    above_100 = {100: 'Hundred',1000:'Thousand', 100000:'Lakhs', 10000000:'Crores'}    if num < 20:         return under_20[num]    if num < 100:        return tens[(int)(num/10)-2] + ('' if num%10==0 else ''+ under_20[num%10])    # find the appropriate pivot - 'Million' in 3,603,550, or 'Thousand' in 603,550    pivot = max([key for key in above_100.keys() if key <= num])    return num2words((int)(num/pivot)) +''+ above_100[pivot] + ('' if num%pivot==0 else ''+ num2words(num%pivot))

But now an error is coming

TypeError : list indices must be integers or slices, not decimal.Decimal

My problem is with decimal numbers, Integer is working fine.


Viewing all articles
Browse latest Browse all 14215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>