473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Money data type

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

Jul 18 '05 #1
3 3345
look at http://fixedpoint.sourceforge.net/ it gives you numeric object
for monetary applications (I have never used it)

--

=*= Lukasz Pankowski =*=
Jul 18 '05 #2
"Batista, Facundo" <FB******@uniFON.com.ar> wrote in message news:<ma**********************************@python. org>...
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).
Jul 18 '05 #3
af*****@yahoo.co.uk (Asun Friere) wrote in message news:<38**************************@posting.google. com>...

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

Umm ...you might want to do the same to __str__ if you want to print ... :/
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing the code. Thank you. .. Facundo
1
by: Jason Szotak | last post by:
Recently we upgraded the .Net Framework to v1.1. All of a sudden all of our queries run through .Net pages began showing all 4 of the decimal places for the money data type. Queries run through asp...
11
by: ZRexRider | last post by:
This may be an easy question but I've been reading for about a half hour and experimenting without results. I simply want the results of my query to display a specific field that is typed...
1
by: Stephane Charette | last post by:
QUICK VERSION: How do I create an index on a field of type "MONEY"? ----------------------------- LONG VERSION: I have a table with a field of type "money". I very often need to access...
4
by: ahaupt | last post by:
Hi all, I'm trying to get a null value into a sql money field through a SqlCommand in c#. However, I get this lovely message (which sparks loads of happy emotions in this overworked body): ...
3
by: Artek | last post by:
Hello, after installing .net 1.1, ASP.NET works fine, but there is a problems with extra zeros added to the numbers at the end. In Sql 2000 SP3a there is for example a table with one column ...
5
by: Ronald S. Cook | last post by:
For money values, C# seems to have just DOUBLE as a type. SQL Server 2005 has data types DECIMAL, FLOAT, MONEY, and NUMERIC that seem to all be able to hold a money time. So, given I'll be...
4
by: Ronald S. Cook | last post by:
We're designing the data model for a project. The app will be in .NET, the database will be in SQL Server 2005. I'm a little confused on type conversion between the two and which I should...
3
by: Stephan Diehl | last post by:
Hi lazyweb, I'm wondering, if there is a usable money data type for python available. A quick search in pypi and google didn't convey anything, even though the decimal data type seemed to be...
1
by: =?Utf-8?B?dHRocm9uZQ==?= | last post by:
Hi, I am querying sql server and loading the resulting data into Excel. For character and integer data types, it's working well, but when I pull decimal data and attempt to load it into Excel...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.