471,339 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

best way of dealing with currency?

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.

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!

Oct 16 '07 #1
5 2692
Just send the currency to me. I'll deal with it.

--
Grant Edwards grante Yow! I'm into SOFTWARE!
at
visi.com
Oct 16 '07 #2
Paul Miller schrieb:
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.

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?
The module decimal. But in the end, you might not be able to recreate
the same values as excel, due to the unknown intricacies of excel.

Diez
Oct 16 '07 #3
On 2007-10-16, Diez B. Roggisch <de***@nospam.web.dewrote:
Paul Miller schrieb:
>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.

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?

The module decimal. But in the end, you might not be able to recreate
the same values as excel, due to the unknown intricacies of excel.
But it can be done! All it takes is a little dedication. Here's a
function that the OP might find useful, for example:

def excel_multiply(a, b):
if a * b != 850 * 77.1:
return a * b
else:
return 100000

Best of luck,
Mark

--
Mark Shroyer
http://markshroyer.com/
Oct 17 '07 #4
On Oct 17, 10:56 am, Mark Shroyer <usenet-m...@markshroyer.comwrote:
On 2007-10-16, Diez B. Roggisch <de...@nospam.web.dewrote:
The module decimal. But in the end, you might not be able to recreate
the same values as excel, due to the unknown intricacies of excel.

But it can be done! All it takes is a little dedication. Here's a
function that the OP might find useful, for example:

def excel_multiply(a, b):
if a * b != 850 * 77.1:
return a * b
else:
return 100000

Best of luck,
Mark
OK joke, but it's worth noting that python's decimal behaves in the
same way as Excel given this example:
>>from decimal import Decimal
850*Decimal('77.1')
Decimal("65535.0")
>>>
Oct 17 '07 #5
On Oct 16, 8:29 pm, Paul Miller <p...@fxtech.comwrote:
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...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!

Oct 17 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Willing 2 Learn | last post: by
3 posts views Thread by Dalan | last post: by
7 posts views Thread by meenasamy | last post: by
25 posts views Thread by mereba | last post: by
2 posts views Thread by (PeteCresswell) | last post: by
reply views Thread by rosydwin | last post: by

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.