From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8bb44fc57f6db2f2 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: Number into String Date: 2000/01/06 Message-ID: <852tjg$fdh$1@nntp9.atl.mindspring.net>#1/1 X-Deja-AN: 569232179 References: <8517up$t0m$1@green.kreonet.re.kr> Organization: MindSpring Enterprises X-Server-Date: 6 Jan 2000 20:23:12 GMT Newsgroups: comp.lang.ada Date: 2000-01-06T20:23:12+00:00 List-Id: In article <8517up$t0m$1@green.kreonet.re.kr>, "Jeong, Lae Hyung" wrote: >NUM : Integer := 123; >How can I convert Integer_value NUM into String_value. Mr. Jeong, Take a look at this little demonstration program I sometimes use in my Ada classes. You may freely copy and modify it. -- ================== Image Demonstration ============== -- Image_Demonstration.adb by Richard Riehle -- This program demonstrates several ways to convert a -- a non-textual value to a string of text. -- -- ===================================================== with Ada.Text_IO; with Ada.Integer_Text_IO; with Ada.Float_Text_IO; use Ada; procedure Image_Demonstration is type Spectrum is (Red, Orange, Yellow, Green, Blue, Indigo, Violet); type Unsigned is mod 2**8; Num : Integer := 451; FNum : Float := 360.0; Color : Spectrum := Blue; MNum : Unsigned := 42; Text : String(1..10); package SIO is new Text_IO.Enumeration_IO(Enum => Spectrum); package MIO is new Text_IO.Modular_IO (Num => Unsigned); package IIO is new Text_IO.Integer_IO (Num => Integer); package FIO is new Text_IO.Float_IO (Num => Float); begin -- Example 1; using the image attribute Text_IO.Put_Line(" Example 1; Using 'Image Attribute "); Text_IO.Put_Line(Spectrum'Image(Color)); Text_IO.Put_Line(Unsigned'Image(MNum)); Text_IO.Put_Line(Integer'Image(Num)); Text_IO.Put_Line(Float'Image(FNum)); Text_IO.New_Line; -- Example 2; using the procedures of pre-instantiated packages Text_IO.Put_Line(" Example 2; using pre-instantiated packages " ); Integer_Text_IO.Put(Num); Text_IO.New_Line; Float_Text_IO.Put (FNum, Fore => 3, Aft => 3, Exp => 0); Text_IO.New_Line(2); -- Example 3; using your own instantiated packages Text_IO.Put_Line(" Example 3; Using own instantiations "); SIO.Put(Color); Text_IO.New_Line; MIO.Put(MNum); Text_IO.New_Line; IIO.Put(Num); Text_IO.New_Line; FIO.Put(FNum, Fore => 3, Aft => 3, Exp => 0); Text_IO.New_Line(2); -- Example 4; convert to text and then print Text_IO.Put_Line("Example 4; Convert to text, then print "); SIO.Put(To => Text, Item => Color); Text_IO.Put_Line(Text); MIO.Put(To => Text, Item => MNum); Text_IO.Put_Line(Text); IIO.Put(To => Text, Item => Num); Text_IO.Put_Line(Text); FIO.Put(To => Text, Item => FNum, Aft => 3, Exp => 0); Text_IO.Put_Line(Text); Text_IO.New_Line; Text_IO.Put_Line("End of Image_Demonstration "); end Image_Demonstration; Richard Riehle http://www.adaworks.com