cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Choose Language Hide Translation Bar
cnattrass
Level II

How do I preserve trailing zeros in a list of numbers?

Hey guys, 

 

I have an application where I need to preserve trailing zeroes for numbers within a list when using the round function. I know trailing zeroes can be preserved in column formatting but the numbers I am working with exist outside of a column object.

 

An example below

 

list_x = {23.04, 24.12,59.632,87.9913};
rounded_x = {};
for(i = 1, i <= nitems(list_x), i++,
	rounded_x[i] = round(list_x[i], 1);
);

show(rounded_x);

The returned list does not show trailing zeroes 

 

rounded_x = {23, 24.1, 59.6, 88};

I looked for ways to force something to a float with specific decimal places but couldnt find anything in the scripting index (at least for the keywords I was using)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
cnattrass
Level II

Re: How do I preserve trailing zeros in a list of numbers?

Landon a coworker of mine and a JMP guru was able to answer the question

 

Here is the solution if anyone else had this question 

 

list_x = {23.04, 24.12,59.632,87.9913};
rounded_x = {};
for(i = 1, i <= nitems(list_x), i++,
	rounded_x[i] = eval(expr(format(round(list_x[i], 1), "Fixed",1)));
);

show(rounded_x);

Returns

rounded_x = {"23.0", "24.1", "59.6", "88.0"};

 

View solution in original post

4 REPLIES 4
cnattrass
Level II

Re: How do I preserve trailing zeros in a list of numbers?

Landon a coworker of mine and a JMP guru was able to answer the question

 

Here is the solution if anyone else had this question 

 

list_x = {23.04, 24.12,59.632,87.9913};
rounded_x = {};
for(i = 1, i <= nitems(list_x), i++,
	rounded_x[i] = eval(expr(format(round(list_x[i], 1), "Fixed",1)));
);

show(rounded_x);

Returns

rounded_x = {"23.0", "24.1", "59.6", "88.0"};

 

Re: How do I preserve trailing zeros in a list of numbers?

How can I modify this easily in the context of a much larger "custom list"? For example, N rows of values exported (populated) into a JMP data table Column?

Re: How do I preserve trailing zeros in a list of numbers?

If you want to retain numeric values, just send the message to the data columnn to set this format.

Re: How do I preserve trailing zeros in a list of numbers?

The original script returned numeric results from the Round() function. The solution returns character string results from the Format() function.