Reading a comma delimited file

Steve Holden sholden at holdenweb.com
Thu Nov 8 13:15:18 EST 2001


"Kristen Zander" <kzander at hot.rr.com> wrote in message
news:%tzG7.2971$qK.174060 at typhoon.austin.rr.com...
> That cleared up alot becuase it was really becoming frustrating.
>
> I just figured it out.
>
> import fpformat
> a = 97.33532356246
> b = fpformat.fix(a,2)
> print b
>
> 97.33
>
> Great!  Thanks.
>
Oops. It probably won't matter, as you seem to have values which are very
close to 2DP anyway, but the example you give above would normally be
expected to be shown as 97.34 (because 97.33532356246 is closer to 97.34
than to 97.33).

The "%.2f" notation should provide this desired behavior, and indeed the
documentation for the fpformat module states: """The fpformat module defines
functions for dealing with floating point numbers representations in 100%
pure Python. Note: This module is unneeded: everything here could be done
via the % string interpolation operator."""

>>> "%.2f" % 97.3353
'97.34'
>>> "%.2f" % 97.3333
'97.33'

look-after-the-places-and-the-decimals-will-look-after-themselves-ly y'rs  -
steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list