[Tutor] printing monetary values

Sean 'Shaleh' Perry shalehperry@attbi.com
Mon, 26 Aug 2002 17:12:31 -0700


On Monday 26 August 2002 05:05 pm, Magnus Lycka wrote:
>
> I think locale.format() looks at decimal separator, grouping
> and thousand separator, but nothing else?
>
> With Swedish setting for instance, your code will write
> "kr3 275,68" instead of the expected "3 275,68 kr".
>
> * It ignores that mon_grouping might differ from grouping and
>    mon_thousands_sep might differ from thousands_sep.
>

i originally had code of the form -- format(string, value, mon_grouping) =
but=20
was told that the final piece was simply a bool and the value was not rea=
d. =20
Suggestions welcome.

> * It should use p_cs_precedes/n_cs_precedes to determine
>    whether the currency symbol goes before or after the value.
>    (And I think, p_sep_by_space/n_sep_by_space to see whether
>    to have a space between the value and the currency symbol.)
>

ooo, I have never seen this talked about.  Spiffy.

> * It should use frac_digits to determine number of decimals,
>    insteqad of a hard coded 2.
>

hmmm, ya it should.

> * locale.format() doesn't care about p_sign_posn / n_sign_posn.
>    A negative amount will be written $-1.00 etc instead of
>    ($1.00) which would be correct.
>

"correct" under certain values of true (-:  It might make sense to displa=
y it=20
as a negative value for some groups and with the (money) notation for oth=
er=20
groups of people.

> It would really be nice to have all this wrapped in a nice
> language independent way. As well as time and date printing
> etc...
>
> Maybe locale should be extended with money_format(),
> int_money_format(), date_time_format() etc... Or perhaps
> even better: The format strings could be extended so that
> locale.format("%m", 4324) would make 4324 into a string
> representation of money and so on.

Indeed this is a lot of replicated code.