best way of dealing with currency?

Paddy paddy3118 at googlemail.com
Wed Oct 17 02:29:30 EDT 2007


On Oct 16, 8:29 pm, Paul Miller <p... at fxtech.com> wrote:
> I'm looking at doing some currency calculations in some Python code
> integrated with a C++ application. I want to be able to come up with the
> same values I get in an Excel spreadsheet.

Ouch! do really want to come up with the Excel result? Sometimes
people have made expensive mistakes when doing financial calculations
in Excel. Part of the problem is Excels calculation errors, and part
is due to spreadsheets being inherently hard to review, and easy to
silently change.

I'd suggest you use Pythons decimal arithmetic module for precise
calculations (i.e. to a precision that you specify), and don't blindly
assume the source of any discrepancies but investigate them
impartially.

(Here's a link to some alarming statistics from a HM customs oficial:
http://www.financeweek.co.uk/cgi-bin/item.cgi?id=5120&d=302&h=24&f=254
).

> I've been poking around for a couple of days and haven't come across a
> definitive method for dealing with currency in a precise manner.
>
> What do I need to do? Use rationals? Very high-precision floating-point?
>   mxNumber? Or something else?
>
> Thanks for any and all input!





More information about the Python-list mailing list