Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Money data type

Reply
Thread Tools

Money data type

 
 
Batista, Facundo
Guest
Posts: n/a
 
      09-17-2003
Can't find it.

I mean something like:

>> m1 = Money(decimal=2)
>> m2 = Money(decimal=2)
>> m1.value = 3.20
>> m2.value = 2.15
>> print m1 + m2

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

 
Reply With Quote
 
 
 
 
Lukasz Pankowski
Guest
Posts: n/a
 
      09-17-2003
look at http://fixedpoint.sourceforge.net/ it gives you numeric object
for monetary applications (I have never used it)

--

=*= Lukasz Pankowski =*=
 
Reply With Quote
 
 
 
 
Asun Friere
Guest
Posts: n/a
 
      09-18-2003
"Batista, Facundo" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Can't find it.
>
> I mean something like:
>
> >> m1 = Money(decimal=2)
> >> m2 = Money(decimal=2)
> >> m1.value = 3.20
> >> m2.value = 2.15
> >> print m1 + m2

> 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 ...

>>> a = Dollars(125.45)
>>> a

$125.45
>>> a + 25.6667

$151.12
>>>



Note this is _not_ to your spec (ie output includes a currency symbol
and input is simply a float).
 
Reply With Quote
 
Asun Friere
Guest
Posts: n/a
 
      09-18-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Asun Friere) wrote in message news:<(E-Mail Removed). com>...
>
> def __repr__ (self) :
> return "$%.2f" % self



Umm ...you might want to do the same to __str__ if you want to print ... :/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET FormView Money Data Type Binding Problem with 2 Decimal Points.. Sam ASP .Net 1 02-11-2010 02:22 PM
Money? What money? It never existed. joevan Computer Support 7 10-13-2008 12:05 PM
Formview (EditView) Money Data Type Binding problem. Help.... Sam ASP .Net Web Controls 0 06-16-2006 11:32 PM
Inserting money type in database from asp.net form! Jensen bredal ASP .Net 3 06-16-2004 04:58 AM
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. luna ASP .Net 1 02-13-2004 01:15 PM



Advertisments