I'm looking for a python library which comes with support to convert numbers between various SI prefixes, for example, kilo to pico, nano to giga and so on.What would you recommend?
I ported a simple function (original C version written by Jukka “Yucca” Korpela) to Python for formatting numbers according to SI standards. I use it often, for example, to set tick labels on plots, etc.
You can install it with:
pip install si-prefix
The source is available on GitHub.
Example usage:
from si_prefix import si_format
print si_format(.5)
# 500.0m (default precision is 1)
print si_format(.01331, precision=2)
# 13.31m
print si_format(1331, precision=2)
# 1.33k
print si_format(1331, precision=0)
# 1k
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With