Categories
Python Answers

How to truncate float values with Python?

Spread the love

Sometimes, we want to truncate float values with Python.

In this article, we’ll look at how to truncate float values with Python.

How to truncate float values with Python?

To truncate float values with Python, we can use the round function.

For instance, we write:

n = round(1.923328437452, 3)
print(n)

to call round with the number to round and the number of decimal places to round to respectively.

And then we assign the rounded number to n.

Therefore, n is 1.923.

Conclusion

To truncate float values with Python, we can use the round function.

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 *