Why not FP for Money?
Bengt Richter
bokr at oz.net
Thu Sep 23 20:10:52 CEST 2004
On Thu, 23 Sep 2004 09:32:34 -0300, Carlos Ribeiro <carribeiro at gmail.com> wrote:
[...]
>
>So, in order to construct a Decimal, I need to write something like:
>
>>>> a = decimal.Decimal('35.72')
>>>> b = decimal.Decimal('1.73')
>>>> a+b
>Decimal("37.45")
>
>But I could write it this way (just an example; my proposed notation
>is for fixed point, not floating point decimal):
>
>>>> a = $35.72
>>>> b = $1.73
>>>> a+b
>$37.45
>
>And it would work. That's nice, clean, and reads quite obviously --
>even if using a symbol as part of the syntax.
I'd prefer not to use up '$' for something that specialized.
ISTM we already have a precedent with longs: i.e., an L suffix. So why not
a D suffix for decimal literals? E.g.,
a = 35.72D # 35.7200D e.g. would specify greater guaranteed precision
b = 1.73D
a+b
37.45D
Regards,
Bengt Richter
More information about the Python-list
mailing list