+ 8

How can I turn a float into its nearest integer in Python3

when I use int() function on a float like 6.6666...., it turns to 66. What can I do to turn it into 67??

11th Mar 2020, 1:59 PM
M Tamim
M Tamim - avatar
2 Réponses
+ 8
There's a function called round. round(6.666) ---> 7 round(3.333) ---> 3 round can take second argument, which tells the accuracy of the rounding. round(1/3, 2) ---> 0.33 round(12345, -3) ---> 12000
11th Mar 2020, 2:01 PM
Seb TheS
Seb TheS - avatar
+ 6
Thank you
11th Mar 2020, 2:03 PM
M Tamim
M Tamim - avatar