MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: question of formatting with PaddedForm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28585] Re: question of formatting with PaddedForm
  • From: Dustin <dsoodak at yahoo.com>
  • Date: Sat, 28 Apr 2001 21:36:10 -0400 (EDT)
  • Organization: University of South Florida
  • References: <9cb95l$ci5@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com


jabauer at oanet.com wrote:

> Hello all,
>
> I am having some difficulties getting a formatted output to look like I
> 'think' it should look. What I want looks like this (three digits, padded
> with leading zeros for numbers less than 100):
>

>
>         Jim

Try this:

In[47]:=
PrintToLength[theNumber_,NumberLength_]:=
  Block[{printstring,strLength=StringLength[ToString[Abs[theNumber]]]},
  If[Sign[theNumber]>=0,printstring=" ",printstring="-"];
  If[strLength<NumberLength,
      printstring=
        StringJoin[printstring,
          FromCharacterCode[Table[48,{NumberLength-strLength}]]]];
  Print[StringJoin[printstring,ToString[Abs[theNumber]]]]
  ];

In[48]:=
For[i = 98, i <= 105,
    PrintToLength[i,3];
    i++]

 098
 099
 100
 101
 102
 103
 104
 105




  • Prev by Date: Re: Interior of a polygon
  • Next by Date: using the escape key for shortcuts
  • Previous by thread: Re: question of formatting with PaddedForm
  • Next by thread: RE: question of formatting with PaddedForm