Suppress Scientific Notation when Printing Float Values in Python (Example)

 

In this tutorial I’ll explain how to avoid scientific notation when printing floats in Python.

The tutorial will be structured as shown below:

 

Creation of Example Data

First, we have to create an example float in Python:

x = 1e-20              # Create example data
print(x)               # Print example data
# 1e-20

As you can see based on the previous console output, we have created a number that is displayed with scientific notation (i.e. “e-20”).

In the following example, I’ll demonstrate how to get rid of the scientific notation. So keep on reading!

 

Example: Do Not Display Scientific Notation When Printing Numbers

This example shows how to print numbers without scientific notation in Python. Have a look at the following syntax and its output:

x_new = f'{x:.30f}'    # Avoid scientific notation
print(x_new)           # Print updated data
# 0.000000000000000000010000000000

As you can see, our float value has been returned with 30 digits after the decimal point.

You may modify the number of digits after the decimal point by changing the number within the previous Python code (i.e. 30).

 

Video, Further Resources & Summary

Have a look at the following video on my YouTube channel. I demonstrate the Python programming code of this tutorial in the video tutorial:

 

 

The following video of the YouTuber Corey Schafer explains how to deal with numeric data in Python. I recommend watching it in case you want to learn more about the handling of numericals and integers:

 

 

In addition to the video, you may have a look at the other Python tutorials on this website. Check out the link below:

 

In summary: In this tutorial, I have explained how to suppress scientific notation when printing float numbers in python. In case you have further questions or comments on this topic, don’t hesitate to let me know in the comments!

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

Top