+ 2
how do you get a float variable to round the decimal to two decimal places in python3
I'm having a bit of trouble with this and I have no idea what to do
4 Respostas
+ 6
Sample, print(round(1.23456,2))
+ 6
Or print(f'{x:.2f}')
+ 1
Another possibility
print('{0:.2f}'.format(x))
https://code.sololearn.com/cOLsJ1p6zd15/?ref=app
0
Use "round" in the following syntax:
print ( round ( [NUM TO ROUND], [NUM OF DEC PLACES] ) )
Here is an example:
>>> x = 1.23456789
>>> print(round(x, 2))
1.23
>>>
Hope that helps