Print number in engineering format

前端 未结 6 1718
陌清茗
陌清茗 2020-12-06 01:22

I am trying to print a number into engineering format with python, but I cannot seem to get it to work. The syntax SEEMS simple enough, but it just doesn\'t work.



        
6条回答
  •  旧时难觅i
    2020-12-06 01:54

    I realize that this is an old thread, but it does come near the top of a search for python engineering notation.

    I am an engineer who likes the "engineering 101" engineering units. I don't even like designations such as 0.1uF, I want that to read 100nF. I played with the Decimal class and didn't really like its behavior over the range of possible values, so I rolled a package called engineering_notation that is pip-installable.

    pip install engineering_notation
    

    From within Python:

    >>> from engineering_notation import EngNumber
    >>> EngNumber('1000000')
    1M
    >>> EngNumber(1000000)
    1M
    >>> EngNumber(1000000.0)
    1M
    >>> EngNumber('0.1u')
    100n
    >>> EngNumber('1000m')
    1
    

    This package also supports comparisons and other simple numerical operations.

    https://github.com/slightlynybbled/engineering_notation

提交回复
热议问题