[issue13060] allow other rounding modes in round()

Aaron Robson report at bugs.python.org
Fri Oct 7 22:22:46 CEST 2011


Aaron Robson <shiny.magnum at googlemail.com> added the comment:

When i run into I have to bodge around it in ways like the below code.

I've only ever used round half up, has anyone here even used Bankers Rounding by choice before?

For reference here are the other options: http://en.wikipedia.org/wiki/Rounding#Tie-breaking

def RoundHalfUp(number):
  '''http://en.wikipedia.org/wiki/Rounding#Round_half_up
  0.5 and above round up else round down.
  '''
  trunc = int(number)
  fractionalPart = number - trunc
  if fractionalPart < 0.5:
    return trunc
  else:
    ceil = trunc + 1
    return ceil

----------
nosy: +AaronR

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13060>
_______________________________________


More information about the Python-bugs-list mailing list