You are on page 1of 1

How to Convert Float Function Into Integer

Goal: Make a print function to change a float function into integer and round it up or down.

Material:

-Python IDE(Pycharm, etc.)

Tools :

-Laptop/Handphone/PC

Steps:

-Firstly, type “import math” in your Python IDE on the first so that math function can be
applied in the coding. I recommend that you use Pycharm, because it it the best IDE for
Python coding.

-Secondly, type a float variable on the second section, for example “a=5.49”

-Next, type “print(int(a))”, this code will convert float function into integer by showing only
the integer of the variable from 5.49 into 5

-And then, use “math.floor” for round the number down and “math.ceil” for round the
number up

-After that, type “print(math.floor(a))” so it will round your number down from 5.49 to 5

-Lastly, type “print(math.ceil(a))” so it will round your number up from 5.49 to 6

___________________________________________________________________________

Tips: If you demand that you shows all the command in one line, you can just type all the
command in print function, for example “print(a, int(a), math.floor(a), math.ceil(a))” it will
print 5.49 5 5 6

You might also like