cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
jc510_2
Level III

Creating a list/box of numbers with variable decimal places

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.

jc510_2_0-1698272888911.png

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.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Creating a list/box of numbers with variable decimal places

(without seeing your original data) Using string col box is most likely the easiest option. You can either get the data in correct format from your original data table or you can convert it before adding values to String Col Box (configuration associative array might be helpful).

 

Format() - Converts the value x into the quoted format that you specify in the subsequent arguments. (scripting index for some good? reason has different description)

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Creating a list/box of numbers with variable decimal places

(without seeing your original data) Using string col box is most likely the easiest option. You can either get the data in correct format from your original data table or you can convert it before adding values to String Col Box (configuration associative array might be helpful).

 

Format() - Converts the value x into the quoted format that you specify in the subsequent arguments. (scripting index for some good? reason has different description)

-Jarmo
jc510_2
Level III

Re: Creating a list/box of numbers with variable decimal places

Thank you for the feedback Jarmo.

After more looking around, I agree with you - it seems like keeping things as strings has more flexibility.  

After my initial post, I came across this nice intro to Col Box -> Text Box approaches, which seems similar to using String Col Box, but gives more flexibility around formatting individual line items (borders, shading, etc.) - https://community.jmp.com/t5/Discovery-Summit-2018/Supercharge-Your-User-Interfaces-in-JSL-US-2018-1....  I'm moving forward with this approach.

After learning about Col Box and thinking about it some more, I realize my original question may have been more along the lines of whether there is a numeric analog of Text Box.  But I don't see such an option.

- Joel

 

jthi
Super User

Re: Creating a list/box of numbers with variable decimal places

Col Box is nice because you can customize it a lot, but it does have its "issues". It is more difficult to get values from it and it also might not behave as you think if you wish to sort by it

Names Default To Here(1);
nw = New Window("Example",
	tb = Table Box(
		scb = String Col Box("strings", {"x", "y", "z"}),
		cb = Col Box(
			"boxes",
			Text Box("a"),
			Text Box("b"),
			Text Box("c")
		)
	);
);

tb << Set Click Sort(1); // try clicking on boxes to sort
Show(tb << get);
Show(scb << get);
Show(cb << get);
Show((cb << XPath("//TextBox")) << get text);

I have also used Col Box when I wanted to have more customization. One example is wanting to have multiple lines for String Col Box. You cannot do that, so you have to use Col Box and Text Box with N Lines (this will force all to be that high though). Or if I want to have Radio Boxes or Check Boxes in table format, Col Box is a good option.

-Jarmo