comp.lang.ada
 help / color / mirror / Atom feed
* Rounding with decimal types
@ 2007-11-26 12:27 Grein, Christoph (Fa. ESG)
  2007-11-26 14:46 ` Wiktor Moskwa
  0 siblings, 1 reply; 6+ messages in thread
From: Grein, Christoph (Fa. ESG) @ 2007-11-26 12:27 UTC (permalink / raw)
  To: comp.lang.ada

For some information about decimal fixed point types and their
differences to ordinary fixed point types, see

http://en.wikibooks.org/wiki/Ada_Programming/Types/delta


Eurocopter Deutschland GmbH
Sitz der Gesellschaft/Registered Office: Donauwoerth
Registergericht/Registration Court: Amtsgericht Augsburg HRB 16508
Vorsitzender des Aufsichtsrates/Chairman of the Supervisory Board: Dr. Lutz Bertling
Geschaeftsfuehrung/Board of Management:
Dr. Wolfgang Schoder, Vorsitzender/CEO; Friedrich-Wilhelm Hormel; Ralf Barnscheidt

CONFIDENTIALITY NOTICE 

This communication and the information it contains is intended for the addressee(s) named above and for no other persons or organizations. It is confidential and may be legally privileged and protected by law. The unauthorized use, copying or disclosure of this communication or any part of it is prohibited and may be unlawful. 
If you have received this communication in error, kindly notify us by return e-mail and discard and/or delete the communication. Thank you very much. 
It is possible for e-mails to be intercepted or affected by viruses. Whilst we maintain virus checks on our e-mails, we accept no liability for viruses or other material which might be introduced with this message. 




^ permalink raw reply	[flat|nested] 6+ messages in thread
* Rounding with decimal types
@ 2007-11-25 15:36 Wiktor Moskwa
       [not found] ` <13kjevsjmhujaa3@corp.supernews.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Wiktor Moskwa @ 2007-11-25 15:36 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-11-26 14:55 UTC | newest]

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

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