Matlab rounding my values without me wanting it

Hello, this basically frustrates me a bit, - if I have:
Price = 20074.5;
And I present it in my table like this:
disp(table(Price,'VariableNames',{'answer'}));
answer
_____
20075
I dont get decimals? Anyone know a way around this? I hope there can be some kind of solution without format long/short because I don't want to touch other things
- Best

Réponses (1)

Walter Roberson
Walter Roberson le 26 Août 2019

1 vote

You get that when format short or format short g or format rat or format hex is in effect.
To work around this without changing your active format, you will need to edit the function getFloatFormats() at roughly line 427 of file toolbox/matlab/datatypes/@tabular/disp.m

6 commentaires

Martin
Martin le 26 Août 2019
thanks for answer. You dont believe there is any other way? I rather want to multiply it by 10 and remember this multiplication
Image Analyst
Image Analyst le 26 Août 2019
Why this great aversion to format long?
Martin
Martin le 26 Août 2019
Answer: due to its such a big system I cant even figure anything out anymore... I cant play with the format...
You could also convert the table entries to character, if you are not planning to do calculations with them.
Note that all that is affected is display of tables not what is stored in the tables. You can also write a function to display the table in whatever format you want.
function disptable(Table)
old_format = matlab.internal.display.format;
format long
disp(Table)
format(old_format)
end
This work but unfortunately it makes the other values in the table very long :/. I only gave a simple table but there are like 20 columns. E.g. I got a percent column where I just need it to show 0.93 but with format long it show:
0.931214019188181

Connectez-vous pour commenter.

Produits

Question posée :

le 26 Août 2019

Commenté :

le 26 Août 2019

Community Treasure Hunt

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

Start Hunting!

Translated by