Python convert float to int

 

Here I will show how to convert a float number to integer using python.

In my script I have a number a = 1.4

a = 1.4

To convert it to integer use following code:

print int(round(a))

After converting float a to integer we will get output as 1.

Add above two line in a script(floatToInt.py) and execute it.

a = 1.5
print int(round(a))

Now execute script with command python floatToInt.py

Output:

1

One comment on “Python convert float to int

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s