Article View: comp.lang.pascal.misc
Article #86Re: Output formatting Question
From: Scott Moore
Date: Tue, 18 Dec 2001 19:32
Date: Tue, 18 Dec 2001 19:32
62 lines
3426 bytes
3426 bytes
comment, this is a great topic, because a lot of folks have this
idea that if the compiler does not supply a built in function for
a particular format, it can't be done. I write the output formatting
functions for IP Pascal completely in standard Pascal. Its slightly
slower than using a "helper" function (like exponent extraction)
but I like the idea that the output functions stand alone.
So if you can write all of the output functions, you can do virtually
any formatting you want. The secret to making it less work is to use
the standard output functions with a little preprocessing as we
have shown here to get exactly want you want with little effort.
Dr John Stockton wrote:
>
> JRS: In article <3C1E75EF.B3A48A0C@cisco.com>, seen in news:borland.pub
> lic.turbopascal, Scott Moore <samiam@cisco.com> wrote at Mon, 17 Dec
> 2001 14:47:11 :-
> >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;
>
> or
>
> function digits(const n : integer) : integer ;
> begin
> {} if n >= 10000 then digits := 5
> else if n >= 1000 then digits := 4
> else if n >= 100 then digits := 3
> else if n >= 10 then digits := 2
> else digits := 1 ;
> end ;
>
> . . .
>
> I've given an effective answer for 2-digit numbers. For a variable
> number of digits K, if speed not crucial, I'd use a while loop ;
>
> Str(M, St) ;
> B := 1 ;
> while St[B]=#32 do begin St[B] := '0' ; Inc(B) end ; {??}
>
> --
> � John Stockton, Surrey, UK. jrs@merlyn.demon.co.uk Turnpike v4.00 MIME. �
> <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
> <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
> <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
--
Insert expressive French girl here.
Technical Details
Message-ID:
<3C1F99D3.41B86396@cisco.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!news.gv.tsc.tdk.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mailReferences:
<3C1A3235.5B88630E@marine.usf.edu> <3C1A4B5C.40DD76DE@yahoo.com> <3C1E75EF.B3A48A0C@cisco.com> <fX7LpQGYLvH8EwjB@merlyn.demon.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111659,4d112d056daac5d7 X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,4d112d056daac5d7 X-Google-Attributes: gid108ebd,public X-Google-Thread: 10261c,4d112d056daac5d7 X-Google-Attributes: gid10261c,public X-Google-ArrivalTime: 2001-12-18 11:30:11 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!news.gv.tsc.tdk.com!sn-xit-02!sn-post-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: Tue, 18 Dec 2001 11:32:35 -0800 Organization: Cisco Systems Inc. Message-ID: <3C1F99D3.41B86396@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> <3C1E75EF.B3A48A0C@cisco.com> <fX7LpQGYLvH8EwjB@merlyn.demon.co.uk> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit 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: 62