0

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??

15th Jun 2020, 3:44 PM
Python piper
Python piper - avatar
2 Answers
+ 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
15th Jun 2020, 3:46 PM
M Tamim
M Tamim - avatar
0
M Tamim thanks, buddy!
15th Jun 2020, 3:47 PM
Python piper
Python piper - avatar