-2

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

4 Answers4

2

With the round function:

round(3.33333333, 3)
Eino Gourdin
  • 4,169
  • 3
  • 39
  • 67
0

You can use format specifiar

num = 3.3333333
print("%.3f"%num)

Output:3.333

Python learner
  • 1,159
  • 1
  • 8
  • 20
0
a=1.233455543323
print('{0:.3f}'.format(a))  

output=1.233

zeeshan12396
  • 382
  • 1
  • 8
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