Re: Re: NumberSigns and Number Formatting

*To*: mathgroup at smc.vnet.net*Subject*: [mg92695] Re: [mg92689] Re: NumberSigns and Number Formatting*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Sat, 11 Oct 2008 06:40:51 -0400 (EDT)*Reply-to*: hanlonr at cox.net

On my system $Version 6.0 for Mac OS X PowerPC (32-bit) (June 19, 2007) the display would not show numbers smaller than -9.999 because there was insufficient space for the number. It worked as expected when I changed Round[{4*fs, fs}] to Round[{4.2*fs, fs}] Bob Hanlon Module[{x = 0., numformat}, numformat[x_] := NumberForm[N[x], {6, 3}, NumberPadding -> {"", "0"}, NumberSigns -> {"-", " "}, SignPadding -> False]; DynamicModule[{fs = 10}, Dynamic@Panel[ Column[{PopupMenu[Dynamic[fs], {10, 12, 14, 16, 18, 20, 22}], Row[{-15 <= "x" <= 15, Spacer[5], Slider[Dynamic[x], {-15, 15, .001}], Spacer[5], InputField[Dynamic[x], FieldSize -> {5, 1.2}]}], Row[{"x:", Spacer[5], Pane[Dynamic[numformat[x]], ImageSize -> Dynamic[Round[{4.2*fs, fs}]], Alignment -> {Right, Baseline}], Spacer[5], "in value."}]}], Style["Number Formatting Problem", 16], BaseStyle -> {FontSize -> fs}]]] ---- Albert Retey <awnl at gmx-topmail.de> wrote: ============= David Park wrote: > I would like to write numbers in a dynamic display such that as the numbers > are varied the width and positioning of the digits, fill spaces, and signs > remained fixed. Now I know that I can do this if I pick a monspace font such > as Courier. However, I would like to do this within Panels and in general > with proportional fonts. The font that is used within Panels is given by > evaluating CurrentValue["PanelFontFamily"] and gives "Segoe UI". It's a nice > looking font and I'm happy with it. I don't want a different font for text > and numbers in a display. > > I assume that with proportional fonts the widths of all the digit characters > are the same. The problem is that the space character is much thinner than > the digits, and + and - are also different widths than the digits. I found > that for NumberPadding on the left I could sometimes use \[LetterSpace] to > match the width of the digits, but I don't think this works for all fonts or > font sizes. Also it leaves a slight trace of its presence, which would be > nice to eliminate. > > Here is a test case to experiment with: > > Module[ > {x = 0., numformat}, > numformat[x_] := > NumberForm[N[x], {6, 3}, NumberPadding -> {"\[LetterSpace]", "0"}, > NumberSigns -> {"-", "\[LetterSpace]"}, SignPadding -> False]; > Panel[ > Column[ > {Row[{-15 <= "x" <= 15, Spacer[5], > Slider[Dynamic[x], {-15, 15, .001}], Spacer[5], > InputField[Dynamic[x], FieldSize -> {5, 1.2}]}], > Row[{"x:", Spacer[5], Dynamic@numformat[x], Spacer[5], > "in value."}] > }], > Style["Number Formatting Problem", 16], > BaseStyle -> {FontSize -> 16}] > ] > > For a FontSize of 16 the LetterSpace works well for the NumberPadding but it > does not work well enough for the NumberSigns. If the FontSize is changed to > 12 then it doesn't work for either. If you vary the slider you will see a > fair amount of jumping around. > > The basic problem here is that NumberPadding and NumberSigns take only > single character strings. The ideal solution would be if one could use: > > NumberPadding -> {Invisible["0"], "0"} > NumberSigns -> {"-", Invisible["-"]} > > but that is not possible. I think your problem is that you are trying at the wrong place. NumberForm is for constructing a string representation of a number, it doesn't care how the string is represented on screen (or paper). To do that there are other functions. I think the following should have the properties you are seeking for and should work with any font you choose (for some you might need to adapt the ImageSize of the Pane) Module[{x = 0., numformat}, numformat[x_] := NumberForm[N[x], {6, 3}, NumberPadding -> {"", "0"}, NumberSigns -> {"-", " "}, SignPadding -> False]; DynamicModule[{fs = 10}, Dynamic@Panel[Column[ { PopupMenu[Dynamic[fs], {10, 12, 14, 16, 18, 20, 22}], Row[{-15 <= "x" <= 15, Spacer[5], Slider[Dynamic[x], {-15, 15, .001}], Spacer[5], InputField[Dynamic[x], FieldSize -> {5, 1.2}]}], Row[{"x:", Spacer[5], Pane[Dynamic[ numformat[x] ], ImageSize -> Dynamic[Round[{4*fs, fs}]], Alignment -> {Right, Baseline}], Spacer[5], "in value."}] }], Style["Number Formatting Problem", 16], BaseStyle -> {FontSize -> fs}] ] ] > Unless someone can suggest a reasonable solution to this maybe it's time > that WRI considered updating NumberFormat. I don't think that WRI would agree that NumberFormat has a problem... hth, albert -- Bob Hanlon

**Re: Unevaluated subtleties**

**Re: NumberSigns and Number Formatting**

**Re: NumberSigns and Number Formatting**

**Re: NumberSigns and Number Formatting**