Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^5: Floating point problems

by Corion (Patriarch)
on Oct 24, 2010 at 09:55 UTC ( [id://867033]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Floating point problems
in thread Floating point problems

Seriously, if you have a multi currency application, consult with the people who actually know how to handle multiple currencies. They will tell you what the market convention is for calculating amounts. The ones I deal with usually calculate conversion rates to 6 fractional digits. Even if you came up with a more (mathematically) correct calculation, you'd still create differences because everyone else uses the market convention. So, talk to the people who know about the market conventions in your market about how to convert between currencies.

If you're not dealing with cross-currency trading, converting back and forth between currencies will obviously introduce rounding errors. You can try to migitate these by using Math::BigRat as long as you only add/subtract/multiply/divide, but I really recommend doing all calculations in one currency and avoiding currency conversions up until the last step. Also see the part about "calculation of error" above - to minimize the introduction of errors through imprecision in the calculations, you'll need to reduce the number of such steps or arrange them in a way that they tend to cancel out each other.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://867033]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-18 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found