Python Forum

Full Version: printing engineering notation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
is there a way to, or a module that can, do this in python for both float and complex?  follow the link in the first comment for details.  ignore the 2nd comment.

https://unix.stackexchange.com/questions...or-numbers
Decimal module has to_eng_string().
Use together with normalize().
λ ptpython
>>> from decimal import Decimal

>>> n = Decimal ('10000000')
>>> n.normalize()
Decimal('1E+7')
>>> n.normalize().to_eng_string()
'10E+6'
engineering_notation
λ pip install engineering_notation
Collecting engineering_notation
Downloading engineering_notation-0.3.3-py3-none-any.whl
Installing collected packages: engineering-notation
Successfully installed engineering-notation-0.3.3
>>> from engineering_notation import EngNumber

>>> n_1 = 10000000
>>> EngNumber(n_1)
10M
>>> EngNumber('10E+6')
10M