How to print the calculation of float with only 3 more decimal If I calculated something and the answer of that calculation is like, 3.33333333... I just want to print it like 3.333 and that's it
Asked
Active
Viewed 73 times
4 Answers
0
You can use format specifiar
num = 3.3333333
print("%.3f"%num)
Output:3.333

Python learner
- 1,159
- 1
- 8
- 20
0
you can use round
function
syntax:
round(number, digits)
number
: Required. The number to be rounded
digits
: Optional. The number of decimals to use when rounding the number. Default is 0
num = 3.33333333
print(round(num, 3))

George Imerlishvili
- 1,816
- 2
- 12
- 20