Why not FP for Money?

Alex Martelli aleaxit at yahoo.com
Fri Sep 24 04:04:28 EDT 2004


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

> aleaxit at yahoo.com (Alex Martelli) writes:
> > > A native Money type, either with the $ signal ($35.72) or the suffix
> > > (35.72D) would not present the same issues, because the literal would
> > 
> > Right, but in practice I find that:
> > 
> > def d(x): return decimal.Decimal(str(x))
> > 
> > appears to work pretty well, judging from early experimentation.
> 
> Hmm.  What does d(35.72) give you?  The same thing as d('35.72')?
> Either answer is arguably wrong.

yep, str(35.72) == '35.72'.  As I use d() only on literals, and will
carefully avoid it if I should ever enter more than six digits in such a
literal, _in practice_ (as I said) I find it works well, whether _in
theory_ it's arguably wrong or not.  Were it a built-in I'd no doubt
have different feelings, but as a handy user-coded one-liner it's fine.


Alex



More information about the Python-list mailing list