Skip to Content
Menu
This question has been flagged
1 Reply
1716 Views

Hi,

I need to change the amount notation to K, M etc..

For example if the amount is 1000 then it should displayed as 1K..

Thanks

Avatar
Discard
Best Answer

Hi,

You can refer the code below.

amount = 2000000
magnitude = 0
while abs(amount) >= 1000:
    magnitude += 1
    amount /= 1000.0
val = '%s%s' % (amount, ['', 'K', 'M', 'G', 'T', 'P'][magnitude])
print(val)

in the above case the output will be 2.0M.You can change the code according to your field name and values.Also refer the following link

https://stackoverflow.com/questions/579310/formatting-long-numbers-as-strings-in-python

Regards

Avatar
Discard