How to Round Up to the Nearest Quarter in Python

This seems to work for me:
math.ceil(val*4)/4

3 Responses to “How to Round Up to the Nearest Quarter in Python”

  1. Christoph says:

    Without using the math module:

    x if 4*x == int(4*x) else int(4*x+1)/4.0

    Rounding down is easier:

    int(4*x)/4.0

  2. Without using the math module, it’s even simpler:

    round(num*4)/4

  3. Sorry :( Missed the round “up” part.