Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
2327 Vues

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
Ignorer
Meilleure réponse

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
Ignorer