473,320 Members | 1,868 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,320 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 2773
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Hicks | last post by:
Is there an accepted best practice on whether to store decimal currency amounts (e.g. dollars and cents) in MySQL decimal column types? Certainly, the most straightforward way is to use decimal...
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
2
by: Willing 2 Learn | last post by:
I'm still having trouble getting my program to do arithmetic in cents(keeping all #'s) then convert the answer in a format of dollars & cents. The main program should add, subtract, scalar...
3
by: Dalan | last post by:
Is there any code available to address currency rounding problems in Access 97? Apparently, selecting currency type table fields does not resolve the problem. For instance, in my form I have a...
1
by: Juan | last post by:
Best way to convert back a currency string into a number(int or long)? If I have, for example, $ 15.000,00 what is the best way to make it again an int or long? pls help!, Juan.
7
by: meenasamy | last post by:
Hi all, i need to create a function that takes three parameters( Original currency, needed currency, amount) i need to convert from the original currency to the needed currency the amount and...
25
by: mereba | last post by:
Hello My country Ghana is changing its currency. I want to write a small programme in C++ that can covert from the old currency into the new one. I would like this programme to run behind a simple...
5
by: BXB | last post by:
I have a number in a table that starts off as currency. There are nulls in the data so I'm trying to convert the nulls to zeros and then wind up back in currency, or in fact in any numeric format. ...
2
by: (PeteCresswell) | last post by:
I'm thinking ISO 4217 as shown on http://www.xe.com/iso4217.php Bond trading system. Users are definitely OK with all of a given security's trades being restricted to a single currency. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.