comp.lang.ada
 help / color / mirror / Atom feed
* Re: Aft, Fore, and Exp
  1999-06-09  0:00 Aft, Fore, and Exp dginc
  1999-06-09  0:00 ` David C. Hoos, Sr.
@ 1999-06-09  0:00 ` Matthew Heaney
  1999-06-09  0:00 ` John Herro
  2 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1999-06-09  0:00 UTC (permalink / raw)


On 09 Jun 1999 15:29, dginc@tds.net wrote:

> Need help on how to use these.  do they go in declaration??  example??
> what i have is my output coming out to 1.98000E+01 and i want it to
> show 19.8 or 20 rounded off.  how do i do this???

See the Exp param to 0:

  Put (Float_Value, Exp => 0);


The operation Put is provided by an instantiation of package
Ada.Text_IO.Float_IO on your floating point type.

If you're using the predefined type Float, then there's an instantation
provided for you already, Ada.Float_Text_IO.









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

* Re: Aft, Fore, and Exp
  1999-06-09  0:00 Aft, Fore, and Exp dginc
  1999-06-09  0:00 ` David C. Hoos, Sr.
  1999-06-09  0:00 ` Matthew Heaney
@ 1999-06-09  0:00 ` John Herro
  2 siblings, 0 replies; 4+ messages in thread
From: John Herro @ 1999-06-09  0:00 UTC (permalink / raw)


dginc@tds.net wants to know how to use Aft, Fore, and Exp

If you don't want your output is scientific notation, set Exp to 0 in the call
to Put.  Aft and Fore tell how many places after and before the decimal point. 
For example, this program produces three spaces followed by 19.8, because it
calls for five places before the decimal point and one after:

with Ada.Float_Text_IO; use Ada.Float_Text_IO;
procedure Test is
  F : Float := 19.8;
begin
  Put(Item => F, Fore => 5, Aft => 1, Exp => 0);
end Test;

- John Herro
You can download a shareware AdaTutor program at
http://members.aol.com/AdaTutor




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

* Re: Aft, Fore, and Exp
  1999-06-09  0:00 Aft, Fore, and Exp dginc
@ 1999-06-09  0:00 ` David C. Hoos, Sr.
  1999-06-09  0:00 ` Matthew Heaney
  1999-06-09  0:00 ` John Herro
  2 siblings, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 1999-06-09  0:00 UTC (permalink / raw)



<dginc@tds.net> wrote in message news:4Lv73.14$ep6.23052@ratbert.tds.net...
> Need help on how to use these.  do they go in declaration??  example??
> what i have is my output coming out to 1.98000E+01  and i want it to show
19.8
> or 20 rounded off.  how do i do this???

Here are some examples:

with Ada.Float_Text_IO;
with Ada.Text_IO;
procedure Rounding is
   The_Value : Float := 19.849;
begin
   Ada.Text_IO.Put_Line (Float'Image (The_Value));
   Ada.Float_Text_IO.Put (The_Value);
   Ada.Text_IO.New_Line;
   Ada.Float_Text_IO.Put
     (Item => The_Value,
      Exp => 0,
      Fore => 3,
      Aft => 3);
   Ada.Text_IO.New_Line;
   Ada.Float_Text_IO.Put
     (Item => The_Value,
      Exp => 0,
      Fore => 3,
      Aft => 2);
   Ada.Text_IO.New_Line;
   Ada.Float_Text_IO.Put
     (Item => The_Value,
      Exp => 0,
      Fore => 3,
      Aft => 1);
   Ada.Text_IO.New_Line;
   Ada.Float_Text_IO.Put
     (Item => The_Value,
      Exp => 0,
      Fore => 3,
      Aft => 0);
   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line(Integer'Image (Integer (The_Value)));
end Rounding;

The output is:
 1.98490E+01
 1.98490E+01
 19.849
 19.85
 19.8
 19.8
 20

Note that in accordance with the Ada Reference Manual A.10.9 (25),
the result for Aft = 0 is the same as for Aft = 0 -- i.e., one
digit follows the decimal point.









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

* Aft, Fore, and Exp
@ 1999-06-09  0:00 dginc
  1999-06-09  0:00 ` David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dginc @ 1999-06-09  0:00 UTC (permalink / raw)


Need help on how to use these.  do they go in declaration??  example??
what i have is my output coming out to 1.98000E+01  and i want it to show 19.8 
or 20 rounded off.  how do i do this???
thanks-dee




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

end of thread, other threads:[~1999-06-09  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-09  0:00 Aft, Fore, and Exp dginc
1999-06-09  0:00 ` David C. Hoos, Sr.
1999-06-09  0:00 ` Matthew Heaney
1999-06-09  0:00 ` John Herro

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