Unnati Shukla Unnati Shukla - 5 months ago 8
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
round(timeDifference)

Answer

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

Difference = round(Difference)