Money data type

B

Batista, Facundo

Can't find it.

I mean something like:
5.35

5.35! Not 5.3500000000000001 neither 5.34999999999999999999.

I think this is not a rare thing, but I can't find it in the standar library
neither the package index.

Thanks!

.. Facundo
 
A

Asun Friere

Batista said:
Can't find it.

I mean something like:

5.35

5.35! Not 5.3500000000000001 neither 5.34999999999999999999.

I think this is not a rare thing, but I can't find it in the standar library
neither the package index.

Thanks!

. Facundo

If it's merely a matter of representing itself you could do something
blindingly simple like:

class Dollars (float) :

def __repr__ (self) :
return "$%.2f" % self

def __add__ (self, other) :
return Dollars(float.__add__(self, other))

#and so on for the other mathematical operators ...


Note this is _not_ to your spec (ie output includes a currency symbol
and input is simply a float).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top