Categories
Python Answers

How to suppress scientific notation when printing float values with Python?

Spread the love

Sometimes, we want to suppress scientific notation when printing float values with Python.

In this article, we’ll look at how to suppress scientific notation when printing float values with Python.

How to suppress scientific notation when printing float values with Python?

To suppress scientific notation when printing float values with Python, we can use the string’s format method with the {:f} format code.

For instance, we write:

a = -7.1855143557448603e-17
s = '{:f}'.format(a)
print(s)

We call format with a as the argument.

{:f} will format the number so that all the digits are in the string.

Therefore, s is -0.000000.

Conclusion

To suppress scientific notation when printing float values with Python, we can use the string’s format method with the {:f} format code.

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 *