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
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ display-scientific-notation-as-float-in-python
Display scientific notation as float in Python - GeeksforGeeks
July 23, 2025 - str.format() formats the number as a float, followed by "e+" and the appropriate power of 10. For example- 340 will be displayed as 3.4e+2 ยท Example: -51000000000.0000000 in scientific notation results in "5.10e+10",where the no. after "e+"denotes ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ display-scientific-notation-as-float-in-python
Display scientific notation as float in Python
In this code, the float() function converts the number in scientific notation to a float format, and the format() method formats the float with two decimal places. The "g" format specifier in Python automatically chooses between fixed and scientific notation based on the number.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ python scientific notation
Python Scientific Notation - Scaler Topics
October 10, 2025 - If we have to format 0.000009732 in Python scientific notation then the code for it will be ยท Here the {:e} in the string is the key point to represent a float value in Scientific Notation while printing the number.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.format_float_scientific.html
numpy.format_float_scientific โ€” NumPy v2.2 Manual
>>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.format_float_scientific.html
numpy.format_float_scientific โ€” NumPy v2.4 Manual
>>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.format_float_scientific.html
numpy.format_float_scientific โ€” NumPy v2.1 Manual
>>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ reference โ€บ generated โ€บ numpy.format_float_scientific.html
numpy.format_float_scientific โ€” NumPy v2.5.dev0 Manual
>>> import numpy as np >>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
Find elsewhere
๐ŸŒ
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 - For this, you can cast the number as an float or decimal or int according to your needs. Python will automatically handle the conversion, but sometimes, for better readability, you might want to format it explicitly. ... The code below converts a scientific notation into a float, decimal and integer form using type casting.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ scientific notation python
Scientific Notation in Python | Delft Stack
March 11, 2025 - Hereโ€™s how you can use f-strings ... a small floating-point number, 0.000123456. By utilizing an f-string, we format this number to two decimal places in scientific notation....
๐ŸŒ
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-float-to-exponential
Python program to convert float to exponential
In this approach, we will use the:e format specifier to format the float number in exponential notation. The :e format specifier tells Python to display the number in scientific/exponential notation.
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python scientific notation: converting and suppressing
Python Scientific Notation: Converting and Suppressing โ€ข datagy
October 24, 2022 - Letโ€™s see how we can create the value of 342 using itโ€™s scientific notation counterpart: # Creating a Value From Scientific Notation value = float(3.42e2) print("value as float: ", value) print(f"value as scientific notation: {value:e}") ...
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ functions โ€บ format.html
format โ€” Python Reference (The Right Way) 0.1 documentation
>>> #This example illustrates the use of [type] option on integers >>> format(2, 'b') '10' >>> format(2, 'b') '10' >>> format(2, 'c') '\x02' >>> format(2, 'd') '2' >>> format(100, 'o') '144' >>> format(100, 'x') '64' >>> format(100, 'n') '100' >>> format(100) '100' >>> #This example illustrates the use of [type] option on floats >>> format(3.13592, 'e') '3.135920e+00' >>> format(3.13592, 'E') '3.135920E+00' >>> format(3.13592, 'f') '3.135920' >>> format(3.13592, 'g') '3.13592' >>> format(3.13592, '.2g') '3.1' >>> format(3.13592, '%') '313.592000%' >>> format(3.13592, '.2%') '313.59%' >>> format(3.13592, 'n') '3.13592'
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ suppressing scientific notation in python for float values
Suppressing Scientific Notation in Python for Float Values - AskPython
April 29, 2023 - In Python, you can suppress scientific notation when printing float values by using the format function.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.0 โ€บ reference โ€บ generated โ€บ numpy.format_float_scientific.html
numpy.format_float_scientific โ€” NumPy v2.0 Manual
>>> np.format_float_scientific(np.float32(np.pi)) '3.1415927e+00' >>> s = np.float32(1.23e24) >>> np.format_float_scientific(s, unique=False, precision=15) '1.230000071797338e+24' >>> np.format_float_scientific(s, exp_digits=4) '1.23e+0024'
๐ŸŒ
Finxter
blog.finxter.com โ€บ how-to-print-a-float-without-scientific-notation-in-python
How to Print a Float Without Scientific Notation in Python? โ€“ Be on the Right Side of Change
The best way to print even small float numbers is to use f-strings, i.e., special types of formatting string that are enclosed in f'...'. Within a given f-string, you can use the {...:.12f} format specifier to tell Python to use floating point precision with 12 digits after the decimal point.