How to round floats into int without importing math | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to round floats into int without importing math

such as 7.89 to 7 and 54.345395 to 54.435

6th Feb 2017, 1:47 AM
JOhn
JOhn - avatar
5 Answers
+ 1
cast using int()
6th Feb 2017, 1:50 AM
Sampath Ganji
+ 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
6th Feb 2017, 3:44 AM
Deddy Tandean
0
What about when it's a number like the other one
6th Feb 2017, 1:59 AM
JOhn
JOhn - avatar
0
use round()
6th Feb 2017, 2:01 AM
Sampath Ganji
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
6th Feb 2017, 10:53 AM
tracy
tracy - avatar