Re: NumberPadding on the left
- To: mathgroup at smc.vnet.net
- Subject: [mg82902] Re: NumberPadding on the left
- From: zac <replicatorzed at gmail.com>
- Date: Fri, 2 Nov 2007 05:05:50 -0500 (EST)
- References: <fg9pq4$n29$1@smc.vnet.net><fgc9qk$90c$1@smc.vnet.net>
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
- Follow-Ups:
- Re: Re: NumberPadding on the left
- From: Carl Woll <carlw@wolfram.com>
- Re: Re: NumberPadding on the left