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.


In reply to Re^5: Floating point problems by Corion
in thread Floating point problems by bluescreen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.