-3

Rounded 0dp to nearest '000s, including its suffix (k/m/t). For example:

        6 --> 6
       23 --> 23
      465 --> 465
     3798 --> 4k
    43423 --> 43k
   910679 --> 911k
  8270192 --> 8m
 23890951 --> 24m
430493245 --> 430m
....

The numbers will be max 999,999,999,999

jesse
  • 105
  • 1
  • 10
  • 3
    Stackoverflow is not your homework-solving community, you should provide the code you tried, issue you're facing, and ask for help on that. – Masked Man Oct 14 '21 at 18:50

2 Answers2

2

Look at the millify package at https://github.com/azaitsev/millify. It seems to do exactly what you want.

Frank Yellin
  • 9,127
  • 1
  • 12
  • 22
2

You can use numerize for this. Documentation here -

#!pip install numerize
from numerize import numerize 

l = [6, 23, 465, 3798, 43423, 910679, 8270192, 23890951, 430493245, 999999999999]

for i in l:
    print(i,'->',numerize.numerize(i))
6 -> 6
23 -> 23
465 -> 465
3798 -> 3.8K
43423 -> 43.42K
910679 -> 910.68K
8270192 -> 8.27M
23890951 -> 23.89M
430493245 -> 430.49M
999999999999 -> 1000B
Akshay Sehgal
  • 18,741
  • 3
  • 21
  • 51