Skip to content

Instantly share code, notes, and snippets.

@nitstorm
Last active December 21, 2015 13:59
Show Gist options
  • Save nitstorm/6316319 to your computer and use it in GitHub Desktop.
Save nitstorm/6316319 to your computer and use it in GitHub Desktop.
A Python3 roundoff function without using the builtin round function (for the LTP skype group). Very amateurish code, doesn't have decimal precision)
def roundoff(number):
##Converts the float to int
whole = int(number)
##Gets the fractal part
frac=number-whole
##Checks the fractal, greater than or equal to 0.5, rounds it up to the next higher digit, else returns the same digit
if frac >= 0.5:
return whole+1
else:
return whole
###Test cases:
print(roundoff(34.16))
print(roundoff(3.6))
print(roundoff(8.5))
print(roundoff(3.01))
print(roundoff(396.99))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment