i have an Amount Object which an Integer that i want to split into Lakhs and Thousands. So for Example say the amount = 2,50,000 i want to split this into lakhs = 2,00,000 and thousands = 50,000.
Currently i am using the following method.
def split_amount(value):
""" A custom method to Split amount into Lakhs and Thousands """
tho, lak = 0, 0
digits = list(str(value))
if len(digits) < 4:
print 'Error : Amount to small to split'
elif len(digits) == 4:
tho = ('').join(digits[-4:])
elif len(digits) == 5:
tho = ('').join(digits[-5:])
elif len(digits) == 6:
tho = ('').join(digits[-5:])
lak = ('').join(digits[-6:])
elif len(digits) >= 7:
tho = ('').join(digits[-5:])
lak = ('').join(digits[-7:])
else:
print "Error : Unknown Error"
if int(tho) <= 0:
thousands = 0
else:
thousands = int(tho)
if (int(lak) - int(tho) <= 0):
lakhs = 0
else:
lakhs = int(lak) - int(tho)
return (lakhs, thousands)
This code looks ugly and i am sure there is a better and a shorter way around. Could you help me achieve what i want in a better way ?
If I’m reading your question correctly, why don’t you just use the modulus operator?