Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Edgar Friendly <thelema314@gmail.com>
Cc: Conglun Yao <yaoconglun@gmail.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Data type representing 'Money'
Date: Sun, 17 May 2009 12:29:55 +0100	[thread overview]
Message-ID: <20090517112955.GB8806@annexia.org> (raw)
In-Reply-To: <4A0F7508.8090705@gmail.com>

On Sat, May 16, 2009 at 09:23:04PM -0500, Edgar Friendly wrote:
> Conglun Yao wrote:
> > Hi all,
> > 
> > Is there any data type could be used to represent 'Money'  in OCaml,
> > similar to BigDecimal.
> > I see a lot of programs using float directly. Maybe Num would be better,
> > but less document could be found, for example, how to represent 20.27
> > 
> > Or there already exist a better solution. Thanks for any help.
> > 
> > Conglun
> > 
> > 
> I'd do fixed point math using Num to count cents (or mills if you really
> need) but displaying dollars and cents.  For example: $20.27 would
> internally be represented by the number 2027, and use int arithmetic for
> exact math.
> 
> If you used 63-bit ints, you'd probably get away with not even using
> Num, as max_int = 4611686018427387903 would represent the dollar amount
> 46_116_860_184_273_879.03, just short of 50 quadrillion dollars.

But be careful if you want to use the software on 32 bit machines.
You won't even be able to represent a single mortgage loss, nevermind
the size of your bailout!

Rich.

-- 
Richard Jones
Red Hat


      parent reply	other threads:[~2009-05-17 11:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-16  7:27 Conglun Yao
2009-05-17  2:23 ` [Caml-list] " Edgar Friendly
2009-05-17  7:10   ` Florent.Ouchet
2009-05-17 16:15     ` Harrison, John R
2009-05-17 11:29   ` Richard Jones [this message]

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=20090517112955.GB8806@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=thelema314@gmail.com \
    --cc=yaoconglun@gmail.com \
    /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