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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,560b069fa82486f6,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.germany.com!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail From: Wiktor Moskwa Newsgroups: comp.lang.ada Subject: Rounding with decimal types Date: Sun, 25 Nov 2007 15:36:39 +0000 (UTC) Organization: tp.internet - http://www.tpi.pl/ Message-ID: NNTP-Posting-Host: aaes14.neoplus.adsl.tpnet.pl X-Trace: nemesis.news.tpi.pl 1196004999 1830 83.4.122.14 (25 Nov 2007 15:36:39 GMT) X-Complaints-To: usenet@tpi.pl NNTP-Posting-Date: Sun, 25 Nov 2007 15:36:39 +0000 (UTC) User-Agent: slrn/0.9.8.1 (Linux) Xref: g2news1.google.com comp.lang.ada:18611 Date: 2007-11-25T15:36:39+00:00 List-Id: Hello, I'm trying to understand how rounding in Ada 95 decimal types works. Reference manual is unfortunately not clear to me on this subject. I declare a decimal type and few variables: type My_Decimal is delta 0.01 digits 18; A, B, C : My_Decimal; I want to have full control over rounding after multiplication and division. Let me post two examples: A := 0.01; B := 0.50; C := My_Decimal (A * B); -- now C = 0.00 A := 0.01; B := 0.50; C := My_Decimal'Round (A * B); -- now C = 0.01 So in the former example the result is truncated towards 0 and in the latter it is rounded away from 0 when the result lies between two integers. That's OK, but is it all that I can do with decimal numbers? How can I round up, down (explicitly) or perform "banker's rounding"? Unfortunately 'Floor 'Ceiling and 'Unbiased_Rounding seem to work only for floating point types. The problem that I'm trying to solve is what type is best suited for financial arithmetic and money representation. Thanks for your help. -- Wiktor Moskwa