caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Joshua Smith" <kognate@gmail.com>
To: caml-list@yquem.inria.fr
Subject: What library to use for arbitrary precision decimals
Date: Sun, 19 Feb 2006 08:43:36 -0500	[thread overview]
Message-ID: <d68fa980602190543g46a86620xfdd584ca2110768d@mail.gmail.com> (raw)

There are a couple of ways to handle money transactions without
rounding errors.

You could use the Nums library, which provides arbitrary precision
calculations and numbers.   But even with arbitrary precision numbers,
you still can have the situation where you get 405.0345 which if this
were USD, you would still have to round if you wanted to pay someone
this amount.  You will still have the arbitrary precision this way,
however.

The best way to handle money (in my experience) is to use integers. 
Then you can define conversion functions but only have to convert it
to decimal for display purposes.  That way, even if you do a million
transactions you won't lose any information.   You can also handle
non-decimal based currencies/instruments/transactions that way[1]

HTH

-jbs

[1] yes,  there are a (thank god shrinking number) of commodities and
stuff like that in the world that don't use decimal prices.


             reply	other threads:[~2006-02-19 13:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-19 13:43 Joshua Smith [this message]
2006-02-19 15:44 ` [Caml-list] " Brian Hurt
2006-02-19 16:38   ` Richard Jones
2006-02-19 16:53     ` Brian Hurt
2006-02-19 17:00       ` Richard Jones
2006-02-19 17:13         ` Richard Jones
2006-02-19 17:21   ` Jeremy Shute
2006-02-19 18:31     ` Brian Hurt
  -- strict thread matches above, loose matches on Subject: below --
2006-02-19 10:18 Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d68fa980602190543g46a86620xfdd584ca2110768d@mail.gmail.com \
    --to=kognate@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).