[Tutor] Re: printing monetary values

Sean 'Shaleh' Perry shalehperry@attbi.com
Mon, 26 Aug 2002 16:39:04 -0700


On Monday 26 August 2002 04:42 pm, Derrick 'dman' Hudson wrote:
> On Mon, Aug 26, 2002 at 02:51:01PM -0700, Sean 'Shaleh' Perry wrote:
> | On Monday 26 August 2002 02:50 pm, Derrick 'dman' Hudson wrote:
> | > I just know I've seen mention before of a library function that
> | > properly formats money as a string, but I can't seem to find it
> | > anywhere.  I want to receive a NUMERIC(15,2) data from a SQL databa=
se
> | > (eg, 3275.68) and have it displayed as $3,275.68.  (dollar sign,
> | > commas, and decimal)  I've searched the Vaults of Parnassus, the
> | > 'locale' module, and comp.lang.python, but didn't find anything exc=
ept
> | > a few partial examples of how to implement it myself.
> |
> | import locale
> |
> | locale.setlocale(locale.LC_ALL, "") # sets locale to the currently
> | defined # value in the user's environment
>
>   **********************************
>

note you can replace the "" with another locale so you can print the same=
=20
string in N different locales by simply changing the locale and calling t=
he=20
code again.

for i in locale_names:
  do_setlocale(i)
  do_show_amount(total)

>
> Bingo!  The line emphasized by the row of stars is the key to making
> this actually work.  Thanks!
>
> -D