Last active
December 21, 2015 13:59
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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