1please subscribe my channel - https://bit.ly/2Me2CfB
2
3import decimal
4
5def currencyInIndiaFormat(n):
6 d = decimal.Decimal(str(n))
7 if d.as_tuple().exponent < -2:
8 s = str(n)
9 else:
10 s = '{0:.2f}'.format(n)
11 l = len(s)
12 i = l-1;
13 res = ''
14 flag = 0
15 k = 0
16 while i>=0:
17 if flag==0:
18 res = res + s[i]
19 if s[i]=='.':
20 flag = 1
21 elif flag==1:
22 k = k + 1
23 res = res + s[i]
24 if k==3 and i-1>=0:
25 res = res + ','
26 flag = 2
27 k = 0
28 else:
29 k = k + 1
30 res = res + s[i]
31 if k==2 and i-1>=0:
32 res = res + ','
33 flag = 2
34 k = 0
35 i = i - 1