On Tue, 2006-06-20 at 13:49 -0400, Paul D. Kraus wrote: > How can i print a float as a currency with commas. > > 1222333.4 -> 1,222,333.40 > > if i '%0.2f'%number > > i get > 1222333.40
import locale >>> locale.setlocale(locale.LC_ALL,"") 'en_US.UTF-8' >>> currency_symbol = locale.localeconv()['currency_symbol'] >>> num = 1222333.4 >>> print currency_symbol + locale.format("%.2f", num, 1) # insert commas $1,222,333.40 > > Thanks, > Paul > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Lloyd Kvam Venix Corp _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor