| Store | Cart

float default formatting

From: Tim Roberts <t...@probo.com>
Sat, 26 Mar 2005 01:00:39 -0800
Bernard Delm?e <bdelmee at advalvas.REMOVEME.be> wrote:
>>Is there a simple way to modify the default sprintf mask>used for floats ? (eg something like sys.float_mask = '%.2f')>I've tried assigning to float.__dict__[ '__str__' ], but>that's apparently not allowed.

No.  The mask string is passed relatively directly to sprintf, with no
hidden charges or destination fees.  %f gets you the whatever your C
library does by default.

This is one way, but there are more efficient methods:

    FLT = "%.2f"
    print ("abc="+FLT+" def="+FLT) % (3.0,4.5)

Are you trying to do currency?  There are better ways, using the locale
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.

Recent Messages in this Thread
Bernard Delmée Mar 24, 2005 10:43 pm
Tim Roberts Mar 26, 2005 09:00 am
Bernard Delmée Mar 26, 2005 12:49 pm
Messages in this thread