Article View: comp.lang.pascal.misc
Article #84Re: Output formatting Question
From: Scott Moore
Date: Mon, 17 Dec 2001 22:47
Date: Mon, 17 Dec 2001 22:47
61 lines
2803 bytes
2803 bytes
Right attack. I use a routine like: function digits(n: integer): integer; var c: integer; begin c := 1; if n > 10 then c := c+1; if n > 100 then c := c+1; if n > 1000 then c := c+1; ... [repeated until max power of bits in integer appears ] digits := c end; Then, this general purpose building block can be used to format numbers in various ways. CBFalconer wrote: > > Jeff Donovan wrote: > > > > I am trying to update some code left by a previous programmer, and > > not knowing Pascal very well I am stuck. Can someone please tell > > me how to add leading zeros to a when outputting an integer. I am > > trying to create a hh:mm:ss time string form integer hours, minutes, > > and seconds variables. > > PROCEDURE write2digs(VAR f : text; n : integer) > > BEGIN > n := abs(n); /* just in case */ > IF (n < 10) THEN write(f, '0', n : 1) > ELSE write(f, n : 2); > END; > > PROCEDURE writedate(VAR f : text; dd, mm, yy, field: integer); > (* in ISO form yyyy-mm-dd with leading zeroes *) > > BEGIN > IF field < 10 THEN field := 10; > write(f, yy : field - 6, '-'); > write2digs(f, mm); > write(f, '-'); > write2digs(f, dd); > END; > > Creation of a writetime should be obvious. > > -- > Chuck F (cbfalconer@yahoo.com) (cbfalconer@XXXXworldnet.att.net) > Available for consulting/temporary embedded and systems. > (Remove "XXXX" from reply address. yahoo works unmodified) > mailto:uce@ftc.gov (for spambots to harvest) -- Insert expressive French girl here.
Technical Details
Message-ID:
<3C1E75EF.B3A48A0C@cisco.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mailReferences:
<3C1A3235.5B88630E@marine.usf.edu> <3C1A4B5C.40DD76DE@yahoo.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,4d112d056daac5d7 X-Google-Attributes: gid111659,public X-Google-Thread: 10261c,4d112d056daac5d7 X-Google-Attributes: gid10261c,public X-Google-Thread: 108ebd,4d112d056daac5d7 X-Google-Attributes: gid108ebd,public X-Google-ArrivalTime: 2001-12-17 14:44:54 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: Scott Moore <samiam@cisco.com> Newsgroups: comp.lang.pascal.misc,borland.public.turbopascal,comp.lang.pascal.borland Subject: Re: Output formatting Question Date: Mon, 17 Dec 2001 14:47:11 -0800 Organization: Cisco Systems Inc. Message-ID: <3C1E75EF.B3A48A0C@cisco.com> X-Mailer: Mozilla 4.73 [en]C-CCK-MCD (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 References: <3C1A3235.5B88630E@marine.usf.edu> <3C1A4B5C.40DD76DE@yahoo.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cache-Post-Path: sj-nntpcache-3!unknown@dhcp-171-71-145-30.cisco.com X-Cache: nntpcache 2.4.0b2 (see http://www.nntpcache.org/) X-Complaints-To: newsabuse@supernews.com Lines: 61