Unnati Shukla Unnati Shukla - 1 year ago 79
Python Question

How to round off <type 'float> number to its nearest integer/whole number in Python?

I have Variable as Follows:

num1 = 491597.379188893
num2 = -17.5438596491228
num3 = 327.480916030534
num4 = 11258.1848115617

How can I round off this numbers to whole numbers giving its values as:

num1 = 491597
num2 = -18
num3 = 327
num4 = 11258

I am using round(number) function which is giving not giving me expected output.

My code looks Like This:

Difference = (Current_UID - Previous_UID)
Difference /= Previous_UID
Difference *= 100

Answer Source

You need to assign the rounded number back to the variable.

Difference = round(Difference)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download