0
How to round floats into int without importing math
such as 7.89 to 7 and 54.345395 to 54.435
5 Answers
+ 1
cast using int()
+ 1
for the first one, you can use casting by using int(). For the second one, you need to use format() to specify how many decimal places you want
0
What about when it's a number like the other one
0
use round()
0
round(float)
rounds float to integer
ie round(23.214) - round to 23
round(float,decimalPoints)
specify in the second argument decimalPoints how many numbers you want it rounded down to
ie round(23.35465,2) - rounding 23.35465 to 2 decimal points