Python Forum
printing engineering notation
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing engineering notation
#1
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
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Forcing matplotlib to NOT use scientific notation when graphing sawtooth500 4 339 Mar-25-2024, 03:00 AM
Last Post: sawtooth500
  ''.join and start:stop:step notation for lists ringgeest11 2 2,416 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  issue with converting a scientific notation to standard notation thomaswfirth 4 1,345 Jun-06-2023, 06:06 PM
Last Post: rajeshgk
  notation MCL169 8 1,449 Apr-14-2023, 12:06 PM
Last Post: MCL169
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,001 Dec-06-2022, 11:09 AM
Last Post: mg24
  Graphics Formatting - X-axis Notation and Annotations - Matplotlib silviover_junior 0 1,778 Mar-17-2021, 01:19 PM
Last Post: silviover_junior
  How to understand the byte notation in python3 blackknite 3 2,899 Feb-23-2021, 04:45 PM
Last Post: bowlofred
  Simple question concerning python dot notation. miner_tom 1 1,902 Mar-24-2020, 05:20 PM
Last Post: buran
  how to implement the .mymethod() notation of Python Pedroski55 4 3,558 Apr-22-2019, 10:24 PM
Last Post: Gribouillis
  Object madness - JSON Notation confusion execsys 4 3,665 May-03-2018, 08:56 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020