473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2788
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.w eb.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...@markshroye r.comwrote:
On 2007-10-16, Diez B. Roggisch <de...@nospam.w eb.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.co mwrote:
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
6346
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 columns. But it appears that such values are stored as ASCII strings, which would be inefficient for calculations (requiring conversion to a...
2
2276
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 windows where you can edit information and data, nothing out of the ordinary. I estimate we have something like 50 to 100 tables and/or views in...
2
574
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 multiply(by int)& show, have a constructor w/ & w/out arguments. Header file should have private data & all 6 functions from above.Class definition file...
3
9378
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 price of item field (say $49.95), and a percentage discount field (say 10% = $5.00), and calculated net cost field of the two. Access seemingly doesn't...
1
5650
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
4054
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 return the new amount in the needed currency, I need this function to work real time (obtaining real time currency exchange rates), any ideas???
25
5912
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 calculator- looking interface. I'm quite new to C++, and I would need some help. Please any suggestion is welcome :) The following is what I...
5
2357
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. I've tried both of these. Add: Format(nz(,0),"Standard") Add: Format(nz(,0),"$#,##0.00") With this I wind up with what looks like numbers...
2
2259
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. They currently claim to even be ok with all of a given fund or portfolio's trades being restricted to a single currency -
0
7425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7682
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7449
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7780
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.