bairui

example of rounding floats

Mar 1st, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.24 KB | None | 0 0
  1. #!/usr/bin/python2
  2.  
  3. def myround(number):
  4.   int_number = int(number)
  5.   remainder = number - int_number
  6.   if remainder < 0.5:
  7.     return int_number
  8.   else:
  9.     return int_number + 1
  10.  
  11. print myround(1.23)
  12. print "\n"
  13. print myround(1.53)
Advertisement
Add Comment
Please, Sign In to add comment