Sometimes, we want to display a decimal in scientific notation with Python.
In this article, we’ll look at how to display a decimal in scientific notation with Python.
How to display a decimal in scientific notation with Python?
To display a decimal in scientific notation with Python, we can use the %.2E
placeholder.
For instance, we write
from decimal import Decimal
n = '%.2E' % Decimal('40800000000.00000000000000')
to format the decimal number to a string version of the number in scientific notation with the %.2E
format placeholder.
Conclusion
To display a decimal in scientific notation with Python, we can use the %.2E
placeholder.