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,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f82a3047082dd83e X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: Newbie Q: Zero fill in Put Date: 1997/09/02 Message-ID: <19970902134901.JAA25393@ladder02.news.aol.com>#1/1 X-Deja-AN: 269524737 References: <340B809C.24AE@home.com> X-Admin: news@aol.com Organization: AOL http://www.aol.com Newsgroups: comp.lang.ada Date: 1997-09-02T00:00:00+00:00 List-Id: Larry Coon writes: > How do I make [integers] output with > leading zeros, eg: 02, 002, 00000002, etc? > The width parameter seems to only fill with > spaces. Here's one way to do it that works in Ada 83 as well as Ada 95. Let J be the integer and W be the width that you want. I assume the integer is non-negative and that it will fit in W spaces. Add J to 10**W (here I assume that this will not overflow). Take the Integer'Image of the result, which will always have a length of W+2 because of the leading space. Select the slice (3 .. W+2). For example, if J is 2 and you want a width of 3, this will print 002: Ada.Text_IO.Put(Integer'Image(1000 + J)(3 .. 5)); Obviously, this works with any integer type. For example, many compilers have Long_Integer. There are other ways to do what you want, but this way is quick and simple if you know that J will never be large enough to cause an overflow. I hope this helps. - John Herro Software Innovations Technology http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor