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)
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"};
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"};
If you want to retain numeric values, just send the message to the data columnn to set this format.
The original script returned numeric results from the Round() function. The solution returns character string results from the Format() function.