Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precision in python

Tags:

python

How can write a print statement in python that will print exactly 2 digits after decimal?

like image 378
Quixotic Avatar asked Mar 08 '11 07:03

Quixotic


People also ask

What is precision in Python?

Python in its definition allows handling the precision of floating-point numbers in several ways using different functions. Most of them are defined under the “math” module.

How do you find the precision in Python?

The precision is the ratio tp / (tp + fp) where tp is the number of true positives and fp the number of false positives. The precision is intuitively the ability of the classifier not to label as positive a sample that is negative. The best value is 1 and the worst value is 0. Read more in the User Guide.

How do you do 2 decimal places in Python?

In Python, to print 2 decimal places we will use str. format() with “{:. 2f}” as string and float as a number. Call print and it will print the float with 2 decimal places.

What is the precision of float in Python?

Double precision numbers have 53 bits (16 digits) of precision and regular floats have 24 bits (8 digits) of precision. The floating point type in Python uses double precision to store the values.


1 Answers

print "{0:.2f}".format(your_number)

This is explained in detail in the Python Documentation.

like image 71
Björn Pollex Avatar answered Nov 13 '22 19:11

Björn Pollex