Is round() broken?

Steve Holden sholden at holdenweb.com
Wed Oct 31 17:23:58 EST 2001


"Joseph Wilhelm" <jwilhelm at outsourcefinancial.com> wrote ...
> Hello again everybody!
>
> I'm having some troubles with round() now... either I'm doing it
completely
> wrong or round() is.  But here's what I'm getting.
>
> >>> round( 43583.010000000002, 2 )
> 43583.010000000002
> >>> round( 43583.010000000002 )
> 43583.0
> >>> round( 43583.010000000002, 1 )
> 43583.0
> >>> round( 43583.010000000002, 2 )
> 43583.010000000002
> >>>
>
> So, what this is saying.. is that rounding to 1 decimal point works... but
> anything beyond that is broken?  Rounding negative will round the number
> before the decimal point also.
>
> And actually, as a side question.. that number was pulled from a float8
> field in a Postgres database, using the 'pg' module. If I look at the
field
> through pgAdmin, I just see it as "43583.01", instead of that whole big
long
> decimal. Is it supposed to come out like this?
>
Rule 1: don't use floating point if you don't understand how it works.

Rule 2: read http://python.sourceforge.net/devel-docs/tut/node14.html

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list