comp.lang.ada
 help / color / mirror / Atom feed
* Re: Data conversion
  1998-10-31  0:00 Data conversion Mat & Syl
@ 1998-10-31  0:00 ` David C. Hoos, Sr.
  1998-10-31  0:00 ` dewarr
  1998-10-31  0:00 ` Pascal MALAISE
  2 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 1998-10-31  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 845 bytes --]


Mat & Syl wrote in message <71fcr5$9to@sifon.cc.mcgill.ca>...
>I need a function to convert float to string and other one for string to
>float.
The language attributes 'Image, and 'Value, respectively, do just that.

Here are the appropriate excerpts from Annex K of the Ada95 Reference
Manual:

88 S�Image For every scalar subtype S:

89 S�Image denotes a function with the following specification:

90 function S'Image(Arg : S'Base)
return String

91 The function returns an image of the value of Arg as a String. See 3.5.

264 S�Value For every scalar subtype S:

265 S�Value denotes a function with the following specification:

266 function S'Value(Arg : String)
return S'Base

267 This function returns a value given an image of the value as a String,
ignoring any leading or trailing spaces. See 3.5.

David C. Hoos, Sr.









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

* Data conversion
@ 1998-10-31  0:00 Mat & Syl
  1998-10-31  0:00 ` David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mat & Syl @ 1998-10-31  0:00 UTC (permalink / raw)


I need a function to convert float to string and other one for string to
float.

            Thanks






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

* Re: Data conversion
  1998-10-31  0:00 Data conversion Mat & Syl
  1998-10-31  0:00 ` David C. Hoos, Sr.
@ 1998-10-31  0:00 ` dewarr
  1998-10-31  0:00 ` Pascal MALAISE
  2 siblings, 0 replies; 5+ messages in thread
From: dewarr @ 1998-10-31  0:00 UTC (permalink / raw)


In article <71fcr5$9to@sifon.cc.mcgill.ca>,
  "Mat & Syl" <slambe@po-box.mcgill.ca> wrote:
> I need a function to convert float to string and other one for string to
> float.


I wonder why this is such a FAQ, when the answer is right there in the
language, namely the Image and Value attributes which of course provide
exactly this functionality. At least in my case when I am teaching Ada, I
teach people about the Image attribute very early (this is my preferred
method for doing integer output for Text_IO, since, unlike Integer_Text_IO it
keeps working fine for derived types when you get to them).



-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Data conversion
  1998-10-31  0:00 Data conversion Mat & Syl
  1998-10-31  0:00 ` David C. Hoos, Sr.
  1998-10-31  0:00 ` dewarr
@ 1998-10-31  0:00 ` Pascal MALAISE
  1998-11-01  0:00   ` dewarr
  2 siblings, 1 reply; 5+ messages in thread
From: Pascal MALAISE @ 1998-10-31  0:00 UTC (permalink / raw)


Mat & Syl wrote:
> 
> I need a function to convert float to string and other one for string to
> float.
> 
>             Thanks
text_io (83) or Ada.Text_IO.Float_IO (95)

private generic
   type Num is digits <>;
package Ada.Text_IO.Float_IO is
...
   procedure Get
     (From : in String;
      Item : out Num;
      Last : out Positive);

   procedure Put
     (To   : out String;
      Item : in Num;
      Aft  : in Field := Default_Aft;
      Exp  : in Field := Default_Exp);
...

-- 
Pascal MALAISE
(priv) mailto:malaise@magic.fr
(prof) mailto:malaise@fr.airsysatm.thomson-csf.com




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

* Re: Data conversion
  1998-10-31  0:00 ` Pascal MALAISE
@ 1998-11-01  0:00   ` dewarr
  0 siblings, 0 replies; 5+ messages in thread
From: dewarr @ 1998-11-01  0:00 UTC (permalink / raw)


In article <363B5ADC.8639CEB0@magic.fr>,
  Pascal MALAISE <malaise@magic.fr> wrote:
> Mat & Syl wrote:
> >
> > I need a function to convert float to string and other one for string to
> > float.
> >
> >             Thanks
> text_io (83) or Ada.Text_IO.Float_IO (95)
>
> private generic
>    type Num is digits <>;
> package Ada.Text_IO.Float_IO is
> ...
>    procedure Get
>      (From : in String;
>       Item : out Num;
>       Last : out Positive);
>
>    procedure Put
>      (To   : out String;
>       Item : in Num;
>       Aft  : in Field := Default_Aft;
>       Exp  : in Field := Default_Exp);
> ...
>
> --
> Pascal MALAISE
> (priv) mailto:malaise@magic.fr
> (prof) mailto:malaise@fr.airsysatm.thomson-csf.com


This is a frequent answer o this FAQ, but for most purposes it is not the
most convenient answer, ESPECIALLY for input, where 'Value is far better.
Usually 'Image is more convenient for output, but of course Put to a string
is more appropriate if you need to control the format.


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-31  0:00 Data conversion Mat & Syl
1998-10-31  0:00 ` David C. Hoos, Sr.
1998-10-31  0:00 ` dewarr
1998-10-31  0:00 ` Pascal MALAISE
1998-11-01  0:00   ` dewarr

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