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
CodePudding user response:
With the round function:
round(3.33333333, 3)
CodePudding user response:
You can use format specifiar
num = 3.3333333
print("%.3f"%num)
Output:3.333
CodePudding user response:
a=1.233455543323
print('{0:.3f}'.format(a))
output=1.233
CodePudding user response:
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))