# Question About Number Format in MATLAB Command Window

27 views (last 30 days)
ercan duzgun on 14 Jan 2021
Commented: ercan duzgun on 14 Jan 2021
% I would like to display a number as a short format. I already executed this command:
format short
% However it doesn't work for some cases. For example, I receive this result:
>> pi
ans =
3.1416
% But I have another variable which I got from solutions of a polynomial.("roots" command)
% If I display those solutions,
% I get long number results. It looks like this:
>> format short
>> disp(x1_sols)
0.74613506773662727719908766254638
0.74624784618189352426025884090749
0.77735277675703701413872152754508
0.82647611867148647532781596815636
1.0679165995745538795723120147744
1.3550488761820195655871374504513
% How can I get short form of this?

John D'Errico on 14 Jan 2021
Edited: John D'Errico on 14 Jan 2021
These are numbers from the symbolic toolbox. That toolbox does not use the format tools to display numbers (though perhaps arguably it could, but that would introduce a whole new set of problms.) You can use vpa to do that.
XX = vpa(1./sym([2;3;7;11;13]))
XX =
0.5
0.33333333333333333333333333333333
0.14285714285714285714285714285714
0.090909090909090909090909090909091
0.076923076923076923076923076923077
vpa(XX,4)
ans =
0.5
0.3333
0.1429
0.09091
0.07692
ercan duzgun on 14 Jan 2021
Thank you @Walter Roberson . Your suggestion is a better solution for me.

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by