Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
2328 Visualizações

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
Cancelar
Melhor resposta

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
Cancelar