round() to nearest .05 ?

tertius terti at mighty.co.za
Tue Nov 16 05:58:14 EST 2004


tertius wrote:
> Hi,
> 
> I'm trying to round my float total to the nearest .05 cents.
> 
> 12.01    should produce 12.00
>  0.14    should produce 0.10
>  2.28          "        2.25
> 703.81         "        703.80
> 
> "%.02f"%100.0099 produces 100.01 (which I know is right)
> No combination of round and/or "%.02f" works for me.
> 
> What's the best way to get there? Should I write a function to manage my 
> rounding or is there a simpler/better way?
> 
> TIA
> T

Thanks for all the help!
I meant nearest towards zero.

chrs
T



More information about the Python-list mailing list