Formatting question : printing numbers with thousands separators ?

Skip Montanaro skip at pobox.com
Fri Aug 31 11:23:42 EDT 2001


 
    Emile> But watch out for negative numbers:
    >>> print locale.format('%.3f',-345.6789,1)
    -,345.679

This might cure that woe:

    n = -345.6789
    sign = (n < 0.0) and "-" or ""
    print "%s%s" % (sign, locale.format('%.3f',abs(n),1))

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list