Subscribe Bookmark RSS Feed

How can I format numbers that are not in a table?

evansorensen0

Community Member

Joined:

Jul 28, 2016

I am trying to format some numbers in a window for an interactive display. I am looking for something like the Format("Best",6) function for columns, but I haven't been able to find how to do that outside of a data table. The round() function isn't quite what I'm looking for because I want to allow the possibility of having very small numbers that would round to 0 if I used the round() function.

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Here is the example from:

    Help==>Scripting Index==>Number Edit Box

that illustrates how to set the format for a Numeric display box

Names Default To Here( 1 );

New Window( "Example",

      fontobj = numbox = Number Edit Box( 0 )

);

numbox << Set Format( Format( "m/d/y", 12 ) );

numbox << Set( Date MDY( 10, 2, 1989 ) );


the Number Box() does not support formating, however, you can use the Number Edit Box() and set Enable(0), to keep users from being able to change the value.

Jim
3 REPLIES
Solution

Here is the example from:

    Help==>Scripting Index==>Number Edit Box

that illustrates how to set the format for a Numeric display box

Names Default To Here( 1 );

New Window( "Example",

      fontobj = numbox = Number Edit Box( 0 )

);

numbox << Set Format( Format( "m/d/y", 12 ) );

numbox << Set( Date MDY( 10, 2, 1989 ) );


the Number Box() does not support formating, however, you can use the Number Edit Box() and set Enable(0), to keep users from being able to change the value.

Jim
pmroz

Super User

Joined:

Jun 23, 2011

The problem with Enable(0) is that the output appears grayed out, hard to read.  I recently had to format some numbers in a number col box, and had to resort to formatting them with format, and then using a string col box to display the output.  Here's some sample code:

// Format numbers with commas

num_list = [100000, 12345, 2212111];

string_list = {};

for (i = 1, i <= nrows(num_list), i++,

    string_list[i] = format(num_list[i], "Fixed Dec", Use thousands separator(1), 13, 0 );

);

nw = new window("Test",

    table box("Formatted Numbers",

        scb = string col box("Numbers", string_list);

    )

);

scb << set justify(right);


By the way the format command  Use thousands separator(1) doesn't work in JMP 11.  Any idea how to get that to work?

pmroz

Super User

Joined:

Jun 23, 2011

OK here's a version that works with either JMP 11 or 12.  Converts the number to USD currency format and strips off the $.  Set Justify doesn't work in 11 either btw.

// Format numbers with commas

num_list = [100000, 12345, 2212111];

jversion = num(words(jmp version(), ".")[1]);

string_list = {};

for (i = 1, i <= nrows(num_list), i++,

    if (jversion <= 11,

        string_list[i] = substr(format(num_list[i], "Currency", "USD", 0 ), 2);

        ,

        string_list[i] = format(num_list[i], "Fixed Dec", Use thousands separator(1), 13, 0 );

    );

);

nw = new window("Test",

    table box("Formatted Numbers",

        scb = string col box("Numbers", string_list);

    )

);

if (jversion > 11,

    scb << set justify(right);

);