MathGroup Archive 2007

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

Search the Archive

Re: Updating NumberPadding?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84329] Re: Updating NumberPadding?
  • From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
  • Date: Wed, 19 Dec 2007 04:15:59 -0500 (EST)
  • Organization: University System of Maryland
  • References: <200712180017.TAA06282@smc.vnet.net> <fk7si4$rl8$1@smc.vnet.net>

Carl,

If you raise Pi to zero or a negative power of ten, your last form below 
does not work correctly, i.e. N[Pi]10^-1 produces 0.31x10.

I agree with David that it would be REALLY nice if WRI made it easier 
for us to produce nice columnar data. I know it is not easy, as the 
examples below show. I know from my FORTRAN days that a lot of CPU 
cycles were used on formatted input and output. Still, it would be nice.

Kevin

Carl Woll wrote:
> David Park wrote:
> 
>> It would certainly be nice if WRI updated NumberPadding so that Style 
>> expressions as well as Strings could be provided for the padding. 
>> Specifically if one uses a font such as Times then NumberPadding -> {" ", 
>> "0"} does not work properly because a single space is not the same width as 
>> the digits, which do all have the same width. Using 
>> Style["0",ShowContents->False] for padding on the right would probably work 
>> but is not allowed.
>>
>>  
>>
> If a fixed width font is out of the question, you could play with the 
> NumberFormat option. For example:
> 
> Column[{
>   NumberForm[N@Pi, {5, 2}, NumberPadding -> {"0", "0"}],
>   NumberForm[N@Pi, {5, 2}, NumberPadding -> {" ", "0"}],
>   NumberForm[N@Pi, {5, 2}, NumberPadding -> {" ", "0"},
>    NumberFormat -> (StringReplace[#1, " " -> ToString[Invisible["0"], 
> TraditionalForm]] &)]}
>  ]
> 
> You will see that the first number and the last number line up properly. 
> If scientific notation is possible, you will need to adjust the 
> NumberFormat accordingly. For instance, the following will take care of 
> scientific notation:
> 
> Column[{
>   NumberForm[N@Pi 10^9, {5, 2}, NumberPadding -> {"0", "0"}],
>   NumberForm[N@Pi 10^9, {5, 2}, NumberPadding -> {" ", "0"},
>    NumberFormat -> (Row[{StringReplace[#1, " " -> 
> ToString[Invisible["0"], TraditionalForm]], 
> "\[ThinSpace]\[Times]\[ThinSpace]",
>         Superscript[#2, #3]}] &)]
>   }]
> 
> You can put an If clause on the third argument, comparing it to "", to 
> cover both cases.
> 
> Carl Woll
> Wolfram Research
> 

-- 

Kevin J. McCann
Research Associate Professor
JCET/Physics
Physics Building
University of Maryland, Baltimore County
1000 Hilltop Circle
Baltimore, MD 21250


  • Prev by Date: Re: disable "disable dynamic updating?"?
  • Next by Date: Re: LinearSolve[m, b] is not equivalent to LinearSolve[m][b]
  • Previous by thread: Re: Updating NumberPadding?
  • Next by thread: Re: Updating NumberPadding?