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
🌐
Cheatography
cheatography.com › brianallan › cheat-sheets › python-f-strings-number-formatting › pdf pdf
Python F-Strings Number Formatting Cheat Sheet
March 16, 2022 - "​Python String Format Cookbo​ok": https:​//m​kaz.bl​og/​cod​e/p​yth​‐ · on-​str​ing​-fo​rma​t-c​ook​book/ si = 55 ​ # small integer · li = 666666 ​ # large integer · sf = 7.77777 ​ # small float · lf = 8888.88 ​ # large float · sc = 9e6 ​ # scientific notation ·
Discussions

Does anyone have a concise cheat sheet for f string formatting with numbers
Here's what I have as a reference. Basically a summary of the Format Specification Mini-Language . This would all go after a : in the f-string curly braces. So if you want a float with 2 decimal place precision, with * as fill and right aligned in a field width of 10 characters you'd do f"{val:*>10.2f}" [[fill]align][sign][#][0][minimumwidth][.precision][type] Fill: Add a character to fill with. Must be followed by Align flag. Align: '<' - Forces the field to be left-aligned within the available space (This is the default.) '>' - Forces the field to be right-aligned within the available space. '=' - Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form '+000000120'. This alignment option is only valid for numeric types. '^' - Forces the field to be centered within the available space. Sign: '+' - indicates that a sign should be used for both positive as well as negative numbers '-' - indicates that a sign should be used only for negative numbers (this is the default behavior) ' ' - indicates that a leading space should be used on positive numbers #: Flags alternate numbering formats; binary, octal, and hexadecimal output will be prefixed with '0b', '0o', and '0x', respectively. 0: Zero-padding. Equivalent to fill '=' and character of '0' Minimumwidth: Min width of the field. Precision: Decimal places for floats or max field size for non-numeric types. Type: Integers: 'b' - Binary. Outputs the number in base 2. 'c' - Character. Converts the integer to the corresponding Unicode character before printing. 'd' - Decimal Integer. Outputs the number in base 10. 'o' - Octal format. Outputs the number in base 8. 'x' - Hex format. Outputs the number in base 16, using lower- case letters for the digits above 9. 'X' - Hex format. Outputs the number in base 16, using upper- case letters for the digits above 9. 'n' - Number. This is the same as 'd', except that it uses the current locale setting to insert the appropriate number separator characters. '' (None) - the same as 'd' Floats: 'e' - Exponent notation. Prints the number in scientific notation using the letter 'e' to indicate the exponent. 'E' - Exponent notation. Same as 'e' except it converts the number to uppercase. 'f' - Fixed point. Displays the number as a fixed-point number. 'F' - Fixed point. Same as 'f' except it converts the number to uppercase. 'g' - General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to 'e' exponent notation. 'G' - General format. Same as 'g' except switches to 'E' if the number gets to large. 'n' - Number. This is the same as 'g', except that it uses the current locale setting to insert the appropriate number separator characters. '%' - Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. '' (None) - similar to 'g', except that it prints at least one digit after the decimal point. More on reddit.com
🌐 r/learnpython
5
3
February 2, 2022
python - Prevent f string from converting float into scientific notation - Stack Overflow
How can I disable this automatic conversion into the scientific notation? And why is it enabled in the first place? Basically the opposite of this question. Edit: I would like to avoid setting a fixed length for the float via {number:.8f} since my numbers have different lengths and I don't want to have any trailing zeros. I want to use the f-strings ... More on stackoverflow.com
🌐 stackoverflow.com
f strings engineering notation
I think this is what you're looking for. More on reddit.com
🌐 r/learnpython
1
3
October 15, 2019
How to convert scientific notation string to integer?
using an integer for scientific notation probably isn't what you want. Use a float. float('1.77e16') More on reddit.com
🌐 r/learnpython
5
1
November 6, 2022
🌐
Pybites
pybit.es › articles › python-f-string-codes-i-use-every-day
Python F-String Codes I Use Every Day – Pybites
April 5, 2024 - val = 0.5 print(f"Example 1: {val:%}") print(f"Example 2: {val:.0%}") ... If you want scientific notation to be printed as such (and not as a regular float) it can be enforced with e or E code.
🌐
Real Python
realpython.com › how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python – Real Python
March 18, 2026 - The first uses the traditional mathematical representation, while the second uses Python’s representation. You won’t be surprised to learn that you can display numbers with scientific notation using format specifiers. Here’s how you do it: ... A common specifier you might use to format numbers in scientific notation is the lowercase (e) presentation type. This uses a lowercase letter e in its display. In the first example, because you set a precision of .2e, your string will display the number in scientific notation rounded to two decimal places.
Top answer
1 of 2
3
Here's what I have as a reference. Basically a summary of the Format Specification Mini-Language . This would all go after a : in the f-string curly braces. So if you want a float with 2 decimal place precision, with * as fill and right aligned in a field width of 10 characters you'd do f"{val:*>10.2f}" [[fill]align][sign][#][0][minimumwidth][.precision][type] Fill: Add a character to fill with. Must be followed by Align flag. Align: '<' - Forces the field to be left-aligned within the available space (This is the default.) '>' - Forces the field to be right-aligned within the available space. '=' - Forces the padding to be placed after the sign (if any) but before the digits. This is used for printing fields in the form '+000000120'. This alignment option is only valid for numeric types. '^' - Forces the field to be centered within the available space. Sign: '+' - indicates that a sign should be used for both positive as well as negative numbers '-' - indicates that a sign should be used only for negative numbers (this is the default behavior) ' ' - indicates that a leading space should be used on positive numbers #: Flags alternate numbering formats; binary, octal, and hexadecimal output will be prefixed with '0b', '0o', and '0x', respectively. 0: Zero-padding. Equivalent to fill '=' and character of '0' Minimumwidth: Min width of the field. Precision: Decimal places for floats or max field size for non-numeric types. Type: Integers: 'b' - Binary. Outputs the number in base 2. 'c' - Character. Converts the integer to the corresponding Unicode character before printing. 'd' - Decimal Integer. Outputs the number in base 10. 'o' - Octal format. Outputs the number in base 8. 'x' - Hex format. Outputs the number in base 16, using lower- case letters for the digits above 9. 'X' - Hex format. Outputs the number in base 16, using upper- case letters for the digits above 9. 'n' - Number. This is the same as 'd', except that it uses the current locale setting to insert the appropriate number separator characters. '' (None) - the same as 'd' Floats: 'e' - Exponent notation. Prints the number in scientific notation using the letter 'e' to indicate the exponent. 'E' - Exponent notation. Same as 'e' except it converts the number to uppercase. 'f' - Fixed point. Displays the number as a fixed-point number. 'F' - Fixed point. Same as 'f' except it converts the number to uppercase. 'g' - General format. This prints the number as a fixed-point number, unless the number is too large, in which case it switches to 'e' exponent notation. 'G' - General format. Same as 'g' except switches to 'E' if the number gets to large. 'n' - Number. This is the same as 'g', except that it uses the current locale setting to insert the appropriate number separator characters. '%' - Percentage. Multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign. '' (None) - similar to 'g', except that it prints at least one digit after the decimal point.
2 of 2
1
A cheat sheet for f-string would be too short and kind of useless since f-string are super simple. If you want to put a number just do it. Ex. name: str = "Albus Dumbledore" age: int = 116 print(f"Name: {name}, Age: {age}") As you can see, I simply put age (which is an int) inside 2 brackets in the string (don't forget the f) and let Python do it's magic. (If you want you can use the example above as your cheat sheet)
🌐
Syntx Scenarios
syntaxscenarios.com › home › python › python scientific notation: how to use, convert & remove it
Python Scientific Notation: How to Use, Convert & Remove it
February 28, 2026 - In Python, you can format numbers in both scientific notation and standard form depending on your requirements. You can use methods such as str.format(), f-strings, and libraries like NumPy and Pandas to switch between these forms for better control over the display of numbers.
Find elsewhere
🌐
datagy
datagy.io › home › python posts › python scientific notation: converting and suppressing
Python Scientific Notation: Converting and Suppressing • datagy
October 24, 2022 - In the example above, we created a variable that would be represented as 1.23e-05 in scientific notation. We then used string formatting in our f-string to display the values as a floating decimal with 7 point precision.
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python how-to's" › "scientific notation in python"
Scientific Notation in Python | Delft Stack
March 11, 2025 - This tutorial demonstrates how to show numbers in scientific notation in Python. Explore various methods, including the built-in format function, f-strings, and the NumPy library, to effectively format large and small numbers. Enhance your data presentation skills with clear examples and detailed ...
🌐
Geeksta
geeksta.net › geeklog › python-number-formatting-f-strings
Python Number Formatting Made Easy with f-Strings | Geeksta
September 12, 2024 - The format_spec is a string that specifies how the variable should be formatted. :d: Format an integer number as a decimal integer. :f: Format a floating-point number as a fixed-point number. :e: Format a floating-point number in scientific notation.
🌐
Python Pool
pythonpool.com › home › tutorials › python scientific notation: e notation, formatting, and conversion
Python Scientific Notation: e Notation, Formatting, and Conversion
July 13, 2026 - Use scientific notation in Python with e and E, format values with f-strings, convert strings, and choose float or Decimal precision deliberately.
🌐
Miguendes
miguendes.me › 73-examples-to-help-you-master-pythons-f-strings
Python F-String: 73 Examples to Help You Master It
July 2, 2022 - How to Format a Number in Scientific Notation (Exponential Notation) Using if-else Conditional in a F-String · How to Use F-String With a Dictionary · How to Concatenate F-Strings · How to Format a Date With F-String · How to Add Leading Zeros · Conclusion · String formatting has evolved quite a bit in the history of Python.
🌐
GeeksforGeeks
geeksforgeeks.org › python › display-scientific-notation-as-float-in-python
Display scientific notation as float in Python - GeeksforGeeks
July 23, 2025 - The scientific notation means any number expressed in the power of 10.for example- 340 can be written in scientific notation as 3.4 X102.in pythons, we use str.format() on a number with "{:e}" to format the number to scientific notation. ...
🌐
Bentley
cissandbox.bentley.edu › sandbox › wp-content › uploads › 2022-02-10-Documentation-on-f-strings-Updated.pdf pdf
A Guide to Formatting with f-strings in Python - CIS Sandbox
There are many ways to represent strings and numbers when using f-strings. The most common · ones that you will need for this course are shown below: ... Decimal Integer. This uses a comma as the number separator character. ... Number. This is the same as d except that it uses the current locale setting to · insert the appropriate number separator characters. ... Exponent notation. Prints the number in scientific notation using the letter ‘e’
🌐
Towards Data Science
towardsdatascience.com › home › latest › an ode to f-stings
An Ode to F-stings | Towards Data Science
March 5, 2025 - For instance, 'e' is the type code for scientific notation. The default expressions type is string or 's'. For fixed-point notation ('f' and 'F' types), the precision value controls the number of digits after the decimal .
🌐
OneUptime
oneuptime.com › home › blog › how to use f-strings for string formatting in python
How to Use f-strings for String Formatting in Python
January 25, 2026 - # Integer formatting num = 42 print(f"Binary: {num:b}") # Binary: 101010 print(f"Octal: {num:o}") # Octal: 52 print(f"Hex: {num:x}") # Hex: 2a print(f"Hex upper: {num:X}") # Hex upper: 2A # Padding with zeros print(f"Padded: {num:05d}") # Padded: 00042 # Float formatting pi = 3.14159265359 print(f"Default: {pi}") # Default: 3.14159265359 print(f"2 decimals: {pi:.2f}") # 2 decimals: 3.14 print(f"5 decimals: {pi:.5f}") # 5 decimals: 3.14159 # Scientific notation large = 1234567890 print(f"Scientific: {large:e}") # Scientific: 1.234568e+09 print(f"Scientific: {large:.2e}") # Scientific: 1.23e+09
🌐
Reddit
reddit.com › r/learnpython › f strings engineering notation
r/learnpython on Reddit: f strings engineering notation
October 15, 2019 -

Python allows printing a number in scientific notation by: f"a:.2e". But does it allow printing in engineering notation without writing my own print function? I know its a small nitpick but my professor LOVES engineering notation.

For the uninitiated, engineering notation is just scientific notation but the 10 is only to the power of numbers divisible by 3. It makes it easier to tell the scale of a unit. i.e.: 12.345e3 vs 1.2345e4.

Even if there isn't a built-in way to handle this if someone has an elegant solution I would appreciate the help.

🌐
Medium
medium.com › bitgrit-data-science-publication › python-f-strings-tricks-you-should-know-7ce094a25d43
Python F-strings Tricks You Should Know | by Benedict Neo | bitgrit Data Science Publication | Medium
October 12, 2022 - scientific notation · pad number with leading zeros :0n where n is the total number of characters · What about large numbers and percentages? Let’s say you have a large number, as large as Apple’s market cap; you can use :, where , is ...
🌐
ZetCode
zetcode.com › python › fstring
Python f-string - formatting strings in Python with f-string
May 11, 2025 - ########42 · F-strings offer precise control over how positive and negative numbers are displayed, including whether to show the plus sign for positive numbers. This is important for financial reports, scientific notation, and any context where the sign of a number matters.