MathGroup Archive 2007

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

Search the Archive

Re: Updating NumberPadding?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84302] Re: [mg84286] Updating NumberPadding?
  • From: Carl Woll <carlw at wolfram.com>
  • Date: Tue, 18 Dec 2007 02:20:43 -0500 (EST)
  • References: <200712180017.TAA06282@smc.vnet.net>

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


  • Prev by Date: Re: LinearSolve[m, b] is not equivalent to LinearSolve[m][b]
  • Next by Date: Mathematica SIG (Washington D.C. and Northern Virginia)
  • Previous by thread: Updating NumberPadding?
  • Next by thread: Re: Updating NumberPadding?