I have following amounts:
1000
1234
123400
1900000
How can i convert these to:
1 Thousand
1.2 Thousand
1.2 Lakhs
19 Lakhs
I tried a function from this link Convert an amount to Indian Notation in Python.
def format_indian(t):
dic = {
4:'Thousand',
5:'Lakh',
6:'Lakh',
7:'Crore',
8:'Crore',
9:'Arab'
}
y = 10
len_of_number = len(str(t))
save = t
z=y
while(t!=0):
t=int(t/y)
z*=10
zeros = len(str(z)) - 3
if zeros>3:
if zeros%2!=0:
string = str(save)+": "+str(save/(z/100))[0:4]+" "+dic[zeros]
else:
string = str(save)+": "+str(save/(z/1000))[0:4]+" "+dic[zeros]
return string
return str(save)+": "+str(save)
But this is giving me:
format_indian(100001)
>>> '100001: 100001'
How can I make that to:1 lakhs
, the above solution only works for 10's of every category. For example: 10 Thousand, 10 Lakhs, 10 crore