round two decimal in table app designer
8 views (last 30 days)
Show older comments
[app.UITableFilteredTable.Data]=Table_HistoricalTable_Struct(app.Eq);
x = [{90} repmat({60},1,size(app.UITableFilteredTable.Data,2)-1)];
app.UITableFilteredTable.ColumnWidth =x;
app.UITableFilteredTable.ColumnName ={};
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1450287/image.png)
i try to use : round(v*100)/100 in table field's but it doesn't work
0 Comments
Accepted Answer
Voss
on 4 Aug 2023
A random matrix:
M = rand(10,2);
A uitable showing that matrix (defaults to 4 decimal places):
figure()
uitable('Data',M);
Another uitable with the numbers rounded to two decimal places:
figure()
uitable('Data',round(M,2));
Another uitable with rounded data, using character vectors instead of numbers:
figure()
t = uitable('Data',compose('%.2f',M),'ColumnFormat',{'char','char'});
Since you are using a uifigure, you can also add a uistyle to the uitable that sets the HorizontalAlignment of the text to the right.
s = uistyle('HorizontalAlignment','right');
addStyle(t,s)
6 Comments
Voss
on 5 Aug 2023
Yes
t = app.UITableFilteredTable; % your uitable
s = uistyle('HorizontalAlignment','center') % 'center' or whatever you want them to be
addStyle(t,s,'column',[1 3:size(t.Data,2)]) % add style s to columns 1 and 3:end of uitable t
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!