I feel like I've been doing something the extra hard way that seems like it should be a relatively straightforward task. Wondering if anyone else has advice on a better approach.
I'm trying to create a custom table like the one shown here, where each of the entries in the "Value" column can have a different number of decimal places. In the example below, "N" should have 0 decimal places, "Mean"/"SD"/"LCL (3SD)"/"UCL (3SD)" should have exactly four decimal places, "Pp" should have exactly two decimal places, etc - with any trailing zeros included. These values are coming from a data table where the values are entered in columns across the first row with the "Stat" column entry as the column headers.
Originally I set this up as a Table Box, with an embedded String Col Box and Number Col Box:
nw = New Window( "nw", tb = Table Box(
scb = String Col Box( "Stat", {}),
ncb = Number Col Box( "Value", {}),
)
);
For( i = 1, i <= N Cols( dt), i++,
tb << Add Row( {Column( dt, i) << Get Name, Column( dt, i)[1] })
);
But it seems the Number Col Box has its own number format setting that applies to all entries in that box.
After much trial and error, what I've found that works is using Char() or Format() (with format/decimal places specified) to convert the individual items from number to character format up front. e.g.,
Column( dt, "Pp")[1] = Format( Round( Column( dt, "Pp")[1], 2), "Fixed Dec", 2);
then replacing the Number Col Box with a second String Col Box and adding the converted values as strings, e.g.,
nw = New Window( "nw", tb = Table Box(
scb1 = String Col Box( "Stat", {}),
scb2 = String Col Box( "Value", {}),
)
);
For( i = 1, i <= N Cols( dt), i++,
tb << Add Row( {Column( dt, i) << Get Name, Column( dt, i)[1] })
);
Is there an easier way I'm missing?
Aside:
- Today I learned that the Format() function converts numeric data to character data. I thought this was just for changing the format of numeric data.
- Today I learned that you can add width and decimal place attributes to Char(). Otherwise it will chop off trailing zeros.