from decimal import Decimal

'%.2E' % Decimal('40800000000.00000000000000')

# returns '4.08E+10'

In your '40800000000.00000000000000' there are many more significant zeros that have the same meaning as any other digit. That's why you have to tell explicitly where you want to stop.

If you want to remove all trailing zeros automatically, you can try:

def format_e(n):
    a = '%E' % n
    return a.split('E')[0].rstrip('0').rstrip('.') + 'E' + a.split('E')[1]

format_e(Decimal('40800000000.00000000000000'))
# '4.08E+10'

format_e(Decimal('40000000000.00000000000000'))
# '4E+10'

format_e(Decimal('40812300000.00000000000000'))
# '4.08123E+10'
Answer from eumiro on Stack Overflow
🌐
Syntx Scenarios
syntaxscenarios.com › home › python › python scientific notation: how to use, convert & remove it
Python Scientific Notation: How to Use, Convert & Remove it
October 21, 2024 - Scientific notation is commonly used in mathematics, physics, finance, and data science to represent extremely large or very small numbers in a compact form. So, instead of writing long strings of zeros, we use powers of 10 to simplify calculations and improve readability. In Python, these numbers are often formatted and displayed inside strings using f-strings and other formatting methods like inserting numeric values into text.
🌐
Scaler
scaler.com › home › topics › python scientific notation
Python Scientific Notation - Scaler Topics
October 10, 2025 - Let's take an example of the ... number above can also be written as ... 9.732 * 10^{-6}9.732∗10−6 can be written as 9.732e-6. Here e is the Exponent symbol....
🌐
Charleston
lemesurierb.people.charleston.edu › python-for-scientific-computing › formatted-output-and-some-text-string-manipulation.html
Formatted Output and Some Text String Manipulation — Python for Scientific Computing
Choosing the number of significant ... width control. The following is slightly ugly due to the shifts right. for exponent in range(11): print(f"4^{exponent} = {4**exponent}")...
🌐
GeeksforGeeks
geeksforgeeks.org › python › display-scientific-notation-as-float-in-python
Display scientific notation as float in Python - GeeksforGeeks
July 23, 2025 - Python3 · # code scientific_format = "{:e}".format(512349000.000000) print(scientific_format) Output: 5.123490e+08 · In the above example, the scientific notation of 512349000.000000 will be a decimal after the first digit and the power of 10 ie- 5.123490 X 108 ·
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › format.html
format — Python Reference (The Right Way) 0.1 documentation
The precise rules are as follows: suppose that the result formatted with presentation type ‘e’ and precision p-1 would have exponent exp. Then if -4 <= exp < p, the number is formatted with presentation type ‘f’ and precision p-1-exp. Otherwise, the number is formatted with presentation type ‘e’ and precision p-1. In both cases insignificant trailing zeros are removed from the significand, and the decimal point is also removed if there are no remaining digits following it.
🌐
Delft Stack
delftstack.com › home › howto › python › scientific notation python
Scientific Notation in Python | Delft Stack
March 11, 2025 - You can use the built-in format() function, f-strings, or the NumPy library to format numbers in scientific notation. What is the difference between ’e’ and ‘E’ in scientific notation?
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.4 Manual
If omitted, the exponent will be at least 2 digits. ... Minimum number of digits to print. This only has an effect for unique=True. In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... Try it in your browser!
🌐
Kitchin Research Group
kitchingroup.cheme.cmu.edu › blog › 2013 › 01 › 21 › Controlling-the-format-of-printed-variables
Controlling the format of printed variables
We use the “e” or “E” format modifier to specify scientific notation. import numpy as np eps = np.finfo(np.double).eps print eps print '{0}'.format(eps) print '{0:1.2f}'.format(eps) print '{0:1.2e}'.format(eps) #exponential notation print '{0:1.2E}'.format(eps) #exponential notation ...
🌐
Sparrow Computing
sparrow.dev › home › blog › scientific notation in python and numpy
Scientific Notation in Python and NumPy - Sparrow Computing
October 15, 2021 - To suppress scientific notation, use <variable>:<width>.<precision>f: ... print("{:.4e}".format(x)) # Expected result # 3.4500e-04 print("%.7f" % x) # Expected result # 0.0003450 · Finally, in NumPy, you can suppress scientific notation with the np.set_printoptions() function:
🌐
Cheatography
cheatography.com › brianallan › cheat-sheets › python-f-strings-number-formatting › pdf pdf
Python F-Strings Number Formatting Cheat Sheet
(a) Let exp = the exponent of y in scientific notation. (b) Is -4 <= exp < p? "​Yes​": Format y using fixed-​point notation and a new precision: p' = p - (1 + exp) where p represents the number of signif​icant · digits before any trailing zeros are removed.
🌐
AskPython
askpython.com › home › suppressing scientific notation in python for float values
Suppressing Scientific Notation in Python for Float Values - AskPython
April 29, 2023 - The mantissa will always represent the main digits of the decimal number. The number should always be represented in base 10, that is, it must always be a decimal number. The value of y in 10y cannot be zero, y>0 or y<0. The absolute value of ...
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.1 Manual
If omitted, the exponent will be at least 2 digits. ... Minimum number of digits to print. This only has an effect for unique=True. In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... >>> import numpy as np >>> ...
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.2 Manual
If omitted, the exponent will be at least 2 digits. ... Minimum number of digits to print. This only has an effect for unique=True. In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... >>> import numpy as np >>> ...
🌐
Python.org
discuss.python.org › ideas
Formatting numbers to string with 'r'-formatting for rounded precision - Ideas - Discussions on Python.org
October 17, 2024 - In high school chemistry I learned to round my results to the number of significant figures given by the precision of the inputs. I now work with chemical engineers and they also practice this way of printing the bottom line. Python number string formatting cannot do this, but other languages can. d3js can format numbers rounded to significant digits. var stringfloat = d3.format(".3r"); d3.select("body").appen...
🌐
Python.org
discuss.python.org › ideas
New format specifiers for string formatting of floats with SI and IEC prefixes - Page 2 - Ideas - Discussions on Python.org
May 20, 2023 - I was thinking of writing a PEP to support formatting floats with SI (decimal) and IEC (binary) prefixes natively for float (and maybe other types if makes sense) but wanted to feel it out first. I’ve implemented what I…
🌐
TutorialsPoint
tutorialspoint.com › python-program-to-convert-int-to-exponential
Python program to convert int to exponential
The process of converting an int to exponential can be achieved using various approaches in Python, such as using the format() function, f-string formatting, or the str.format() method. These methods allow us to format an integer number in scientific notation by specifying the appropriate format ...
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.format_float_scientific.html
numpy.format_float_scientific — NumPy v2.5.dev0 Manual
If omitted, the exponent will be at least 2 digits. ... Minimum number of digits to print. This only has an effect for unique=True. In that case more digits than necessary to uniquely identify the value may be printed and rounded unbiased. New in version 1.21.0. ... Try it in your browser!
🌐
Code Redirect
coderedirect.com › questions › 441831 › exponent-digits-in-scientific-notation-in-python
[Solved] Exponent digits in scientific notation in Python - Code Redirect
class MyNumber: def __init__(self, val): self.val = val def __format__(self,format_spec): ss = ('{0:'+format_spec+'}').format(self.val) if ( 'E' in ss): mantissa, exp = ss.split('E') return mantissa + 'E'+ exp[0] + '0' + exp[1:] return ss print( ...