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=1.8 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 9E1B9BC37 for ; Sun, 17 May 2009 04:23:09 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYBAKgRD0rRVdmekGdsb2JhbACXFD8BAQEBCQkMBxEDpnGBE48oAQMBA4N+BQ X-IronPort-AV: E=Sophos;i="4.41,206,1241388000"; d="scan'208";a="40098390" Received: from mail-gx0-f158.google.com ([209.85.217.158]) by mail4-smtp-sop.national.inria.fr with ESMTP; 17 May 2009 04:23:09 +0200 Received: by gxk2 with SMTP id 2so5160310gxk.3 for ; Sat, 16 May 2009 19:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=Mko7bKBstX9SsLz4BA0ijGzRvwoShX6zGYSBpioopEE=; b=hM9290T6sZndvB0A+ef7zj00hcVHR4zTl7wkssRw+qZjCGCPqEzV3CfLKBHbAV68IK l4SE1mjlQ5bl5ZqxYuJ3rVBecfpHgkOFjh+TuiumcqrBnWrj3mP54PQ1ec760OLM7G1M BwB0Werjb4JQPbk30v5RhayKHaMAvoUgmtS0o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=vTeurY5bR8IrcMPY6Rii1z9OjksWPG6Gxp9Nm7mdF7HrqR2mnPFQFbj6MDdaddaKte Am7mue+Z4fCiIBJLfz2s5WSG2/9ta0rN5PiB+7cKrp6cxguVlp2IVZKmB/KbKuR+uqQn hDMped9YKvXX5BqYRwfRT63tFIUNTpTK4K5KI= Received: by 10.150.202.11 with SMTP id z11mr9424196ybf.129.1242526987925; Sat, 16 May 2009 19:23:07 -0700 (PDT) Received: from ?192.168.0.11? (adsl-69-154-216-28.dsl.stlsmo.swbell.net [69.154.216.28]) by mx.google.com with ESMTPS id 5sm8883606ywd.35.2009.05.16.19.23.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 16 May 2009 19:23:07 -0700 (PDT) Message-ID: <4A0F7508.8090705@gmail.com> Date: Sat, 16 May 2009 21:23:04 -0500 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 To: Conglun Yao , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Data type representing 'Money' References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 edgar:98 mills:98 wrote:01 ints:01 caml-list:01 arithmetic:01 short:01 int:01 int:01 data:02 data:02 represented:02 float:03 representing:05 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. E