Python Numerize Library

Numerize is that library of python which is used to show large numbers into its readable format. It basically converts numerical format into the compact short format. There is no need to show how many zeroes are behind the number. It itself checks the numeric digits behind the coefficient and then provides output in the compact short form accordingly.

Key Feature

It enhances the understanding as there is no need to write a number of zeroes behind the number coefficient(also called as trailing zeroes).

Examples:

1 -> 1
10 -> 10
100 -> 100
1000 -> 1k
1500 -> 1.5k
1000000 -> 1M
1000000000 -> 1B
1000000000000 -> 1T

Note:

  • Here k represents thousand (i.e. coefficient will have 3 trailing digits ), M represents Million (i.e. coefficient will have 6 trailing digits), B represents Billion (i.e. coefficient will have 9 trailing digits)and T represents Trillion (i.e. coefficient will have 12 trailing digits).
  • It will convert numerical numbers only up to 100T.

Installing Library

To install this module type tehe below command in the terminal.



pip install numerize 

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

from numerize import numerize 
  
a = numerize.numerize(100)
print(a)
  
a = numerize.numerize(1000)
print(a)
  
a = numerize.numerize(1500)
print(a)
  
a = numerize.numerize(1000000)
print(a)
  
a = numerize.numerize(1123456)
print(a)
  
a = numerize.numerize(10000000000)
print(a)

chevron_right


Output:

100
1k
1.5k
1M
1.12M
10B

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

from numerize import numerize 
  
  
# Here we can also get number upto 
# any decimal place
a = numerize.numerize(1234567.12, 2)
print(a)
  
a = numerize.numerize(1247854, 4)
print(a)
  
a = numerize.numerize(12134.123, 3)
print(a)

chevron_right


Output:

1.23M
1.2479M
12.134K



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.