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