Integer in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Integer in python

When doing numeric operation in python it always returns float. But what if i need integer . Even if the result is a whole number it returns float. Like if the result is 7 it returns 7.0. But i want integer. How can i do that. ( Is there any way to transform float into int.)

29th Sep 2020, 1:59 PM
Khalid Shifullah
Khalid Shifullah - avatar
6 Answers
29th Sep 2020, 2:01 PM
RuntimeERROR
RuntimeERROR - avatar
+ 2
Netha_r2071 Thanks a lot bro. This is exactly what i ment.
29th Sep 2020, 2:10 PM
Khalid Shifullah
Khalid Shifullah - avatar
+ 1
Khalid Shifullah see the same code using round () function https://code.sololearn.com/cKN5Rdk3CQqv/?ref=app
29th Sep 2020, 2:32 PM
RuntimeERROR
RuntimeERROR - avatar
+ 1
Netha_r2071 thanks again😍 . dude you are too good
29th Sep 2020, 2:34 PM
Khalid Shifullah
Khalid Shifullah - avatar
+ 1
Use int() function 👍👍
30th Sep 2020, 5:29 PM
Dark Killer
Dark Killer - avatar
0
Netha_r2071 bro what if i want the output to be rounded. Like if it is 7.8 i want 8. How i do it . import math?
29th Sep 2020, 2:29 PM
Khalid Shifullah
Khalid Shifullah - avatar