From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bc1441bb4023e50f X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!t54g2000hsg.googlegroups.com!not-for-mail From: Graham Stark Newsgroups: comp.lang.ada Subject: Re: Financial Calculations in Ada Date: Mon, 21 Jul 2008 01:24:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <860d1$4883ccd5$45490079$7570@KNOLOGY.NET> NNTP-Posting-Host: 86.161.177.145 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1216628669 8063 127.0.0.1 (21 Jul 2008 08:24:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 21 Jul 2008 08:24:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t54g2000hsg.googlegroups.com; posting-host=86.161.177.145; posting-account=04rmagoAAABZ9PN7u3MdbKIs6DPG57E- User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9) Gecko/2008051202 Firefox/3.0,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1233 Date: 2008-07-21T01:24:29-07:00 List-Id: On Jul 21, 12:27=A0am, rd <162...@gmail.com> wrote: > I'm playing around some with Ada, and today started with the > intent of cooking up a crappy mortgage calculator. =A0I did the > obvious: > > =A0 =A0 =A0type Money is delta 0.01 digits 12; > =A0 =A0 =A0package MIO is new Ada.Text_IO.Decimal_IO (Money); use MIO; > > I hit a brick wall more quickly than usual in that I couldn't > figure out a good way to handle interest rates that might have > a decimal value with more digits than my Money type, such as 7.125. > > Can anyone give me any tips on how to handle this sort of thing > in Ada? > > -- > rd I've been doing something similar. I would use float types if you can, not least because the root-finding algorithms you'll have to use probably won't work with discrete types. As someone else mentioned, financial institutions will have policies on exactly where and how money amounts are rounded, but it's unlikely you'll capture that just by relying on a Decimal type.