Categories
Python Answers

How to display a decimal in scientific notation with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *