By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

best way of dealing with currency?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.