Advertisement
Guest User

Untitled

a guest
Sep 9th, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. def human_format(num):
  2. num = int(num)
  3. if num < 1000:
  4. return num
  5. magnitude = 0
  6. while abs(num) >= 1000:
  7. magnitude += 1
  8. num /= 1000.0
  9. # thousands, millions, billions, trillions, quadrillion
  10. return '%.2f%s' % (num, ['', 'K', 'M', 'B', 'T', 'Qd', 'Qt', 'S', 'Qd', 'Qt', 'S', 'Oc', 'Non', 'Dec'][magnitude])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement