comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Rounded off
Date: 1999/06/09
Date: 1999-06-09T00:00:00+00:00	[thread overview]
Message-ID: <mozxXkus#GA.225@newstoo.hiwaay.net> (raw)
In-Reply-To: 7jmq0c$uq$1@nnrp1.deja.com


<dennison@telepath.com> wrote in message news:7jmq0c$uq$1@nnrp1.deja.com...
> In article <jKz73.34$ep6.34762@ratbert.tds.net>,
>   dginc@tds.net wrote:
> > i am wondering how to have my output come out rounded insted of with
> > decimals??  the output is 19.8 figured from calculation, i want it to
> output
> > that rounded off (20).  the calculation is from float a decimal and
> input is a
> > whole number.  any suggestions
> >
> 
> 
> How about:
>  Integer(X + 0.5)
>
The above suggestion will give wrong results for negative numbers.

Real values are already rounded on conversion to Integer (RM 4.6 (33),
viz.:
If the target type is an integer type and the operand type is real, the
result is rounded to the nearest integer (away from zero if exactly
halfway between two integers).

So simply Integer (X) will give correct results for all values of X
within the range of type Integer.

For rounding to, say, the nearest 0.01, one should use an instantiation
of the appropriate generic package from Ada.Text_IO, and use an Aft
value of 2 when calling the Put procedure.  Rounding is done by the
Put procedure. 







  reply	other threads:[~1999-06-09  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-09  0:00 Rounded off dginc
1999-06-09  0:00 ` dennison
1999-06-09  0:00   ` David C. Hoos, Sr. [this message]
1999-06-10  0:00     ` Robert Dewar
1999-06-10  0:00   ` Robert Dewar
1999-06-14  0:00     ` William Dale
1999-06-15  0:00     ` czgrr
replies disabled

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