Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Re: NumberPadding on the left

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82906] Re: [mg82902] Re: NumberPadding on the left
  • From: Carl Woll <carlw at wolfram.com>
  • Date: Sat, 3 Nov 2007 03:21:24 -0500 (EST)
  • References: <fg9pq4$n29$1@smc.vnet.net><fgc9qk$90c$1@smc.vnet.net> <200711021005.FAA20065@smc.vnet.net>

zac wrote:

>Thanks for pointing that out.
>Based on this information, I've written a simple function to simulate
>the behaviour I wanted to achieve:
>
>In[19]:=
>Needs["Utilities`FilterOptions`"];
>
>DigitForm::usage="DigitForm[expr, {l,
>r}] prints expression with exactly r numerical digits on the right
>(rounding \
>fractional part) and exactly l (or more, if needed) numerical digits
>on the \
>left side of the decimal point.";
>
>Options[DigitForm]={NumberPadding\[Rule]{"0","0"}};
>DigitForm[num_,{l_,r_},opts___?
>OptionQ]:=Module[{pad,left},pad=NumberPadding/.\
>{opts}/.Options[DigitForm];
>      left=If[l==="Default",1,l];
>      pad=If[l==="Default",{"",pad[[2]]},pad];
>      NumberForm[N[num],{left+r,r},NumberPadding\[Rule]pad,NumberSigns\
>[Rule]{\
>If[Negative[num],"-",""],
>        ""},SignPadding\[Rule]True,FilterOptions[NumberForm,opts]]];
>
>
>DigitForm[#,{3,2}]&/@{.001,.1,1,11,-11,111,-111,Rational[8,10]}
>
>
>Out[23]=
>{000.00,000.10,001.00,011.00,-011.00,111.00,-111.00,000.80}
>
>which prints exactly those numbers I need.
>
>If anyone could come up with a more simple function, please let me
>know that!
>
>Istvan
>
>  
>
Why don't you use:

NumberSigns->{"-"," "}

or

NumberSigns->{"-","\[InvisibleSpace]"}

instead?

Carl Woll
Wolfram Research


  • Prev by Date: Re: Setting Negatives to Zero
  • Next by Date: Re: Re: NDSolve with functions of vectors
  • Previous by thread: Re: NumberPadding on the left
  • Next by thread: Re: MultivariateDistribution mathematica 6