comp.lang.ada
 help / color / mirror / Atom feed
* Help: Truncating Decimal Types
@ 1997-12-30  0:00 John J. Cupak Jr.
  1997-12-30  0:00 ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: John J. Cupak Jr. @ 1997-12-30  0:00 UTC (permalink / raw)



A student tried to extract the integer portion of a decimal (money)
value using Money_Type'Truncation(Cash), and received the GNAT error
that the attribute is only for Float types (That's what the ARM says,
too).

Does anyone have an easy way to extract the integer portion of a decimal
number - short of writing a function? Seems Ada should allow this (and
other attributes) for fixed and decimal types, but it doesn't without
first converting the value to decimal.

Thanks
-- 
----------------------------------------------------------------
-                   John J. Cupak Jr, CCP                      -
- Raytheon Electronic Systems: Software Engineering Laboratory -
- tel: 508-858-1222     email (work): jcj@swl.msd.ray.com      -
- fax: 508-858-4336     email (home): jcupak@aol.com           -
----------------------------------------------------------------




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

* Re: Help: Truncating Decimal Types
  1997-12-30  0:00 Help: Truncating Decimal Types John J. Cupak Jr.
@ 1997-12-30  0:00 ` Robert Dewar
  1998-01-02  0:00   ` Peter Hermann
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Dewar @ 1997-12-30  0:00 UTC (permalink / raw)



John asks

<<Does anyone have an easy way to extract the integer portion of a decimal
number - short of writing a function? Seems Ada should allow this (and
other attributes) for fixed and decimal types, but it doesn't without
first converting the value to decimal.
>>

	
This is trivial, just convert it to a decimal type whose delta is 1.0.
The default for such conversions is truncation. 





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

* Re: Help: Truncating Decimal Types
  1997-12-30  0:00 ` Robert Dewar
@ 1998-01-02  0:00   ` Peter Hermann
  1998-01-02  0:00     ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Hermann @ 1998-01-02  0:00 UTC (permalink / raw)



Robert Dewar (dewar@merv.cs.nyu.edu) wrote:
> John asks

> <<Does anyone have an easy way to extract the integer portion of a decimal
> number - short of writing a function? Seems Ada should allow this (and
> other attributes) for fixed and decimal types, but it doesn't without
> first converting the value to decimal.
> >>

> 	
> This is trivial, just convert it to a decimal type whose delta is 1.0.
> The default for such conversions is truncation. 

This is indeed new to me. It seems I have to change my mind.
I always thought that the Ada rule is most easily rememberable
in that 
   -- conversions will round,
   -- integer divisions will truncate.

puzzled

--
Peter Hermann  Tel:+49-711-685-3611 Fax:3758 ph@csv.ica.uni-stuttgart.de
Pfaffenwaldring 27, 70569 Stuttgart Uni Computeranwendungen
Team Ada: "C'mon people let the world begin" (Paul McCartney)




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

* Re: Help: Truncating Decimal Types
  1998-01-02  0:00   ` Peter Hermann
@ 1998-01-02  0:00     ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1998-01-02  0:00 UTC (permalink / raw)



Peter says

<<This is indeed new to me. It seems I have to change my mind.
I always thought that the Ada rule is most easily rememberable
in that
   -- conversions will round,
   -- integer divisions will truncate.

puzzled
>>

The rules for decimal are different, for good reasons.





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

end of thread, other threads:[~1998-01-02  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-30  0:00 Help: Truncating Decimal Types John J. Cupak Jr.
1997-12-30  0:00 ` Robert Dewar
1998-01-02  0:00   ` Peter Hermann
1998-01-02  0:00     ` Robert Dewar

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