Answer the question
In order to leave comments, you need to log in
How to correctly implement the reduction of large numbers?
Recently it was necessary to write a system for reducing numbers, that is, 1.000 - 1K, 2.000.000 - 2M. I came up with a simple solution for myself:
def shortint(textint):
textint = str(textint)
m = {0: '', 3: 'K', 6: 'M', 9: 'B', 12: 'T'}
k = (len(textint)-1)//3*3
if k == 0:
return textint
else:
return textint[:-k] + m[k]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question