Monday, August 18, 2008

Seriously brain-dead way to round off numbers in Python

import decimal
def Round(value, precision = 3):
return float(str(
decimal.Decimal(str(value)).quantize(decimal.Decimal("1")
/ (decimal.Decimal('1' + '0' * precision)), decimal.ROUND_HALF_UP)))

Labels:

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home