Thursday, December 31, 2009

How do I round numbers to a specific value in python programming?eg:1154 to nearest 20 or 50 or 200 or 500?

I am using Python 2.5 and usually want to round UP, so directional rounding is important too.


ThanksHow do I round numbers to a specific value in python programming?eg:1154 to nearest 20 or 50 or 200 or 500?
Find the modulus of a number and then subtract or add. e.g in Python:





1154 % 20 == 14





Then you can add/subtract 14 from 1154
  • nba players
  • No comments:

    Post a Comment