Skip to content

Instantly share code, notes, and snippets.

@russell310
Created September 17, 2019 06:41
Show Gist options
  • Select an option

  • Save russell310/844c208125b153596a0eca49a351f52e to your computer and use it in GitHub Desktop.

Select an option

Save russell310/844c208125b153596a0eca49a351f52e to your computer and use it in GitHub Desktop.
Bangladeshi money format system in python
def int_to_word(num):
d = {0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five',
6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten',
11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen',
15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen',
19: 'nineteen', 20: 'twenty',
30: 'thirty', 40: 'forty', 50: 'fifty', 60: 'sixty',
70: 'seventy', 80: 'eighty', 90: 'ninety'}
k = 1000
l = k * 100
c = l * 100
b = c * 10000000
assert (0 <= num)
if (num < 20):
return d[num]
if (num < 100):
if num % 10 == 0:
return d[num]
else:
return d[num // 10 * 10] + ' ' + d[num % 10]
if (num < k):
if num % 100 == 0:
return d[num // 100] + ' hundred'
else:
return d[num // 100] + ' hundred and ' + int_to_word(num % 100)
if (num < l):
if num % k == 0:
return int_to_word(num // k) + ' thousand'
else:
return int_to_word(num // k) + ' thousand ' + int_to_word(num % k)
if (num < c):
if num % l == 0:
return int_to_word(num // l) + ' lac'
else:
return int_to_word(num // l) + ' lac ' + int_to_word(num % l)
if (num < b):
if (num % c) == 0:
return int_to_word(num // c) + ' crore'
else:
return int_to_word(num // c) + ' crore ' + int_to_word(num % c)
raise ValueError('num is too large: %s' % str(num))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment