comp.lang.ada
 help / color / mirror / Atom feed
From: Wiktor Moskwa <wiktorDOTmoskwa@gmail.com>
Subject: Rounding with decimal types
Date: Sun, 25 Nov 2007 15:36:39 +0000 (UTC)
Date: 2007-11-25T15:36:39+00:00	[thread overview]
Message-ID: <fic4q7$1p6$1@nemesis.news.tpi.pl> (raw)

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



             reply	other threads:[~2007-11-25 15:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-25 15:36 Wiktor Moskwa [this message]
     [not found] ` <13kjevsjmhujaa3@corp.supernews.com>
2007-11-26  8:15   ` Rounding with decimal types Wiktor Moskwa
2007-11-26 13:47     ` Dmitry A. Kazakov
2007-11-26 14:55       ` Wiktor Moskwa
  -- strict thread matches above, loose matches on Subject: below --
2007-11-26 12:27 Grein, Christoph (Fa. ESG)
2007-11-26 14:46 ` Wiktor Moskwa
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox