Currency format for floats?

Bjorn Pettersen bjorn at roguewave.com
Fri Jun 2 17:28:34 EDT 2000


Andrew Dalke wrote:
> 
> Joseph Santaniello wrote:
> >Ah, yes. But I'm still missing my commas [for 23,342.40]... A nice
> > clean way to do that?
> 
> I think the following is only somewhat tricky, but perhaps the
> cleanest.  (Okay, there's also supposed to be a way to do this with
> locale, but I don't know how.)

import locale
locale.setlocale(locale.LC_ALL,"")  # set to default locale
locale.format('%.2f', 5555.555, 3)  # (format, value, grouping)
# outputs 5,555.56 on my system

--bjorn




More information about the Python-list mailing list