From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 4057DBBAF for ; Sun, 17 May 2009 13:29:56 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ak0EAKmRD0pQRFuwWWdsb2JhbACXSwEWFQS4EoQBBQ X-IronPort-AV: E=Sophos;i="4.38,431,1233529200"; d="scan'208";a="29459620" Received: from furbychan.cocan.org ([80.68.91.176]) by mail1-smtp-roc.national.inria.fr with ESMTP; 17 May 2009 13:29:56 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1M5eZ1-0002MM-GS; Sun, 17 May 2009 12:29:55 +0100 Date: Sun, 17 May 2009 12:29:55 +0100 To: Edgar Friendly Cc: Conglun Yao , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Data type representing 'Money' Message-ID: <20090517112955.GB8806@annexia.org> References: <4A0F7508.8090705@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4A0F7508.8090705@gmail.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; ocaml:01 2009:98 edgar:98 mills:98 wrote:01 wrote:01 ints:01 caml-list:01 arithmetic:01 short:01 int:01 int:01 data:02 data:02 represented:02 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