<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2006/02/6a4ece1ab3283a32cdfc79d59c82478d"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2006-02-19T15:44:16"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals"
  prev="2006/02/dfa9c0a2577effa6597ec330bf48dce3"
  next="2006/02/7ced1cf6716695b05c93739612f75c5d"
  prev-in-thread="2006/02/e0d80c67993d25b72681b783bd13813a"
  next-in-thread="2006/02/34c5b33a2ce71032c5bfbac81e30432f"
  prev-thread="2006/02/26e0e034e81973bfaabae58148b29f96"
  next-thread="2006/02/7ced1cf6716695b05c93739612f75c5d"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/e0d80c67993d25b72681b783bd13813a"
  from="Joshua Smith &lt;kognate@g...&gt;"
  author="Joshua Smith"
  date="2006-02-19T13:43:38"
  subject="What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/6a4ece1ab3283a32cdfc79d59c82478d"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2006-02-19T15:44:16"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/34c5b33a2ce71032c5bfbac81e30432f"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2006-02-19T16:38:42"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/72ee455a5f011374a71925238a2ed762"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2006-02-19T16:53:25"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/92ca6367f5929b8a8d393bd551a0f41c"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2006-02-19T17:01:16"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/ea5f7ca7239b2b1d32ef4a745dbed037"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2006-02-19T17:13:26"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2006/02/024932e2e2c8b5b06b83662881c27c24"
  from="Jeremy Shute &lt;shutej@g...&gt;"
  author="Jeremy Shute"
  date="2006-02-19T17:21:44"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
<msg 
  url="2006/02/463692f8dc009e6672589f4cbd97f837"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2006-02-19T18:31:14"
  subject="Re: [Caml-list] What library to use for arbitrary precision decimals">
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>


On Sun, 19 Feb 2006, Joshua Smith wrote:

&gt; There are a couple of ways to handle money transactions without
&gt; rounding errors.
&gt;
&gt; You could use the Nums library, which provides arbitrary precision
&gt; calculations and numbers.   But even with arbitrary precision numbers,
&gt; you still can have the situation where you get 405.0345 which if this
&gt; were USD, you would still have to round if you wanted to pay someone
&gt; this amount.  You will still have the arbitrary precision this way,
&gt; however.
&gt;
&gt; The best way to handle money (in my experience) is to use integers.
&gt; Then you can define conversion functions but only have to convert it
&gt; to decimal for display purposes.  That way, even if you do a million
&gt; transactions you won't lose any information.   You can also handle
&gt; non-decimal based currencies/instruments/transactions that way[1]

I agree with this recommendation.  The basic idea is that you use fixed 
point.  Say you want to be accurate to one thousandth of a cent (0.001 
cents).  You simply do all calculations in terms of millicents.  So the 
integer 1 represents one millicent.  One penny is represented as the 
integer 1,000- one thousand millicents.  The amount $2,345.67 is 
represented by the integer 234,567,000.

If you use the Int64 module as the basis for your computations, you can 
hold values up to $184,467,440,737,095.51 in size.  This is larger than 
the world's GDP, so it should be large enough.  32 bits isn't enough- that 
only allows you to hold values up to $42,949.67.

Brian

</contents>

</message>

