def quantize(number, digits=<NUM_LIT:0>, q=builtins.round):
base, fraction = split(digits)<EOL>if fraction * <NUM_LIT:10> % <NUM_LIT:1> > <NUM_LIT:0>:<EOL><INDENT>digits = base + <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>digits = base + <NUM_LIT:1><EOL><DEDENT>multiplier = <NUM_LIT:10> ** base * invert(fraction, default=<NUM_LIT:1>)<EOL>quantized = q(number * multiplier) / multiplier<EOL>return builtins.round(quantized, digits)<EOL>
Quantize to somewhere in between a magnitude.

For example:

    * ceil(55.25, 1.2) => 55.26
    * floor(55.25, 1.2) => 55.24
    * round(55.3333, 2.5) => 55.335
    * round(12.345, 1.1) == round(12.345, 2) == 12.34