🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.misc
Article #85

Re: Output formatting Question

#85
From: Dr John Stockton
Date: Tue, 18 Dec 2001 07:40
45 lines
2662 bytes
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.
Technical Details
Message-ID: <fX7LpQGYLvH8EwjB@merlyn.demon.co.uk>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!news.demon.co.uk!demon!merlyn.demon.co.uk!spam
References: <3C1A3235.5B88630E@marine.usf.edu> <3C1A4B5C.40DD76DE@yahoo.com> <3C1E75EF.B3A48A0C@cisco.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10261c,4d112d056daac5d7
X-Google-Attributes: gid10261c,public
X-Google-Thread: 111659,4d112d056daac5d7
X-Google-Attributes: gid111659,public
X-Google-Thread: 108ebd,4d112d056daac5d7
X-Google-Attributes: gid108ebd,public
X-Google-ArrivalTime: 2001-12-17 23:43:01 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!news.demon.co.uk!demon!merlyn.demon.co.uk!spam
From: Dr John Stockton <spam@merlyn.demon.co.uk>
Newsgroups: comp.lang.pascal.misc,borland.public.turbopascal,comp.lang.pascal.borland
Subject: Re: Output formatting Question
Date: Tue, 18 Dec 2001 07:40:08 +0000
Organization: Home, 'Surrey', UK
Message-ID: <fX7LpQGYLvH8EwjB@merlyn.demon.co.uk>
References: <3C1A3235.5B88630E@marine.usf.edu> <3C1A4B5C.40DD76DE@yahoo.com>
 <3C1E75EF.B3A48A0C@cisco.com>
Reply-To: Dr John Stockton <reply@merlyn.demon.co.uk>
NNTP-Posting-Host: merlyn.demon.co.uk
X-NNTP-Posting-Host: merlyn.demon.co.uk:158.152.233.145
X-Trace: news.demon.co.uk 1008661326 nnrp-12:21631 NO-IDENT merlyn.demon.co.uk:158.152.233.145
X-Complaints-To: abuse@demon.net
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain;charset=iso-8859-1
X-Newsreader: Turnpike (32) Version 4.00  <FaPHOaas0ellLCXbR0oIxSiVaE>
Lines: 45