Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- How do I preserve trailing zeros in a list of numbers?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 23, 2019 2:20 PM
(1314 views)

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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"};`

4 REPLIES 4

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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"};`

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Learn it once, use it forever!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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.

Learn it once, use it forever!

Article Labels

There are no labels assigned to this post.