# Eliminate decimals past the thousandths place in a table

4 views (last 30 days)
camicat on 20 Jan 2020
Edited: camicat on 22 Jan 2020
I have a table being pulled from a database that contains 'string' and 'double' data that being a parameter name and it's associated limits. I am currently trying to eliminate replicate data using the unique function however some of the data that is considered duplicated is not removed because it has either 14 or 16 trailing zeros. I would like to eliminate the zeros past the thousandths place.
Fix, Ceil, Round, and Floor do not work with tables.

James Tursa on 20 Jan 2020
Please upload a sample of the actual data you are working with, along with your exact desired output for this data.
Adam Danz on 21 Jan 2020
If those values are considered unique by the unique() function that eliminates the possibility that you're just using a long format such as
format long
but if those values are numeric, it suggests that they have some trailing non-zero decimal values, otherwise they wouldn't end in a string of 0s.
You could round all of your values to the thousandths place by using
round(x,3)
Image Analyst on 21 Jan 2020

Adam Danz on 21 Jan 2020
If those values are considered unique by the unique() function that eliminates the possibility that you're just using a long format such as
format long
but if those values are numeric, it suggests that they have some trailing non-zero decimal values, otherwise they wouldn't end in a string of 0s.
You could round all of your values to the thousandths place by using
round(x,3)

camicat on 22 Jan 2020
I'm using unique(table(:,3:end),'rows') which would omit the first 2 columns when going through the table. It works for 98% of the data except the two batches I talked about where I come across an issue. Even if the values for those rows have non-zero decimal values past the trailing zeros as you suggested, for my purposes they are considered the same if they have the same number to the thousandths place, which is why I need to round the numbers or chop them after the thousandths place.
I am trying to list unique groups of values by row, not by column, so each row has the same number of columns.
Thank you for your help thus far!
Walter Roberson on 22 Jan 2020
uniquetol()
Adam Danz on 22 Jan 2020
Yeah, I'd try Walter's suggestion first by replacing the unique function my previous comment with uniquetol. If that doesn't work, you could play around with tolerance level. See C = uniquetol(A,tol)
If all else fails, you can round that column of data using
T.Var = round(T.Var,3);
where T is your table and var is the column's variable name.