From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 5C325BBBB for ; Sun, 19 Feb 2006 14:43:38 +0100 (CET) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.207]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k1JDhbIq004860 for ; Sun, 19 Feb 2006 14:43:37 +0100 Received: by zproxy.gmail.com with SMTP id 9so759033nzo for ; Sun, 19 Feb 2006 05:43:36 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=UkMCOp4/J5pHJNPRrNVbd9krwqAUiHqfgCAzy6zZH39+d17aRytNp8lfrPvSvPCcnaxsXJMrHx73Ijxa1oTdJNi+rPZo87Ho0Eako/JDebZDNg7NJhXL/RZedJERx/vdVkxucu28VzKhvkALUOvDJt0gafxMKVRQOP4hoWzcERI= Received: by 10.65.225.19 with SMTP id c19mr190089qbr; Sun, 19 Feb 2006 05:43:36 -0800 (PST) Received: by 10.65.83.18 with HTTP; Sun, 19 Feb 2006 05:43:36 -0800 (PST) Message-ID: Date: Sun, 19 Feb 2006 08:43:36 -0500 From: "Joshua Smith" To: caml-list@yquem.inria.fr Subject: What library to use for arbitrary precision decimals MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Miltered: at concorde with ID 43F87609.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; rounding:01 integers:01 instruments:98 arbitrary:01 arbitrary:01 functions:01 define:01 nums:01 library:03 library:03 usd:94 prices:93 million:93 stuff:08 gmail:09 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 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.=20 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.