COM and currency conversion

John notehead2 at hotmail.com
Sun May 6 22:19:06 EDT 2001


Wow. That's unfortunate to hear. I was planning on using Python's unittest
module (formerly PyUnit) to test COM objects and database writes which deal
with pricing. Can you or anyone here explain the tuple format that the
currency types are converted to? (See the examples below.) If I understand
what's going on there -- and it seems like I should but I don't -- then I
can still write the unit tests.

-John



"Mark Hammond" <MarkH at ActiveState.com> wrote in message
news:3AF5F3A9.90607 at ActiveState.com...
> John wrote:
>
>  > I've run into another issue with using ADO/SQL Server with Python.
>  > It has to  do with how money fields come across in Python. Python
>  > converts the money  field into a 2 value tuple. Anyone know the way
>  >  to get a meaningful dollar  about back out? Here are some examples
>  >  of dollar amounts and their  representation in Python:
$1,234,567.01
>  >  == (2, -539231788)  $1,000,000.00 == (2, 1410065408)  $2,000,000.00
>  >  == (4, -1474836480)
>
>       This is a little sad.  Python has no support at all for these.  The
> basic problem is that there is no Python type to convert it to.  It you
> dig on MSDN, you will find this represents a fixed decimal point number.
>   In the interests of being correct when Tim may be watching <wink> it
> is exactly:
> "A currency number stored as an 8-byte, two's complement
> integer, scaled by 10,000 to give a fixed-point number with 15 digits to
> the left of the decimal point and 4 digits to the right.  This
> representation provides a range of 922337203685477.5807 to
> -922337203685477.5808"
>
>   I have discussed this with Tim, and he agrees in general that
> conversion to float would be evil, and there is no better type.  He has
> suggested I rip out his "FixedPoint.py"
>
(ftp://ftp.python.org/pub/python/contrib-09-Dec-1999/DataStructures/FixedPoi
nt.py)and
> use that.  However, there is also implication that Python will grow
> something like this as a core datatype, so I don't want to lock everyone
> into FixedPoint when something more natural may be just around the corner.
>
> Mark.
>
>





More information about the Python-list mailing list