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,22b2c05a8088bbb2 X-Google-Attributes: gid103376,public X-Google-Thread: 101deb,495b037244521cf3,start X-Google-Attributes: gid101deb,public From: rav@goanna.cs.rmit.edu.au (robin) Subject: Re: Leading zeros with Int_IO.Put()? Or another package? Date: 1996/11/08 Message-ID: <55ubsh$lh0$1@goanna.cs.rmit.edu.au>#1/1 X-Deja-AN: 195208643 references: <327FB8A3.745B@itg-sepg.logicon.com> organization: Comp Sci, RMIT, Melbourne, Australia newsgroups: comp.lang.ada,comp.lang.pl1 nntp-posting-user: rav Date: 1996-11-08T00:00:00+00:00 List-Id: David Shochat writes: >J.D. Baldwin wrote: >> My question: is there a better way to pad out integers with leading >> zeros? >Whenever I need leading zeros (in any radix), I use what we call here >the "Everage Maneuver" (named after fellow Logiconer Amy Everage, who >came up with this years ago). Lets say we want to put the nonnegative >integer n to a field of k characters with radix r using leading zeros if >necessary. So we assert n < r**k. >1. Convert n + r**k to a string. This uses k+1 characters, the 1st of >which is '1', representing r**k. >2. Use all but the 1st character from the result of (1). Interface to PL/I and you can use standard I/O: put edit (n) (P'-99999999'); and you don't have to worry about whether the number is negative either. The nines in the picture format force leading zeros to print. And if you want, you can insert commas in the output to make it more readable. The picture specification becomes: P'-999,999,999'