MATLAB Answers


How can I change it to display decimal number?

Asked by Maria Coronell on 20 May 2013
Latest activity Commented on by Walter Roberson
on 21 Apr 2017

Hi, there.. I'm solving simple ecuation in matlab but when i run the programe the answer is displaying in fractional numbers. How can I change it to display decimal number?


"format short" and "format long" have no effect on symbolic numbers or symbolic expressions.

Hi, I have the same problem too. I try format short but the answer still fraction number.

Kantaphon, see my Answer below.

Log in to comment.


No products are associated with this question.

3 Answers

Answer by Walter Roberson
on 21 May 2013

It looks to me like you have calculated values using the symbolic toolbox. To display those values in floating point, use double() on them. For example,


(If we had known you were using the symbolic toolbox we could have answered much earlier.)


Thanks, it works.. but before, I didnt have to put any command to have my decimal numbers, thats what i want. I don't know if the problem is that i have to change some toolbox or what.. but if you know how to do it please, I'll appreciate.

In most cases, the Symbolic Toolbox will convert formulae involving floating point numbers into their rational fractions.

When the Symbolic Toolbox is working with a rational formula, it will attempt to find a closed-form solution, but if it cannot do so then (if meaningful) it will attempt to find a fixed-point numeric solution instead.

When the Symbolic Toolbox recognizes that it is working with a fixed-point formula (rather than rational) then it will skip trying to find a closed-form solution and will proceed with trying to find a fixed-point numeric solution.

Because of the above behavior, two formulae that are the same except for a single decimal point in one of them, might be calculated different ways and can potentially arrive at very different answers; for example a formula with a complex term might have the term cancel out to 0 when calculated in full rational precision, but might have a large non-zero complex term when calculated in fixed-point.

For example, at the MuPAD command line,

int(x^2+1, x=0..10^10)

would proceed by closed-form, but if the "1" was replaced by "1." then it would do a numeric calculation.

Now, if you have a symbolic term that is in rational form and you add a constant, then if the constant is in rational form the addition would b done in rational form; if, however, the constant is in fixed-point form then the rational symbolic term will be evaluated down to a fixed-point number before the addition is done.

1 + RATIONALTERM  gives a rational answer
1. + RATIONALTERM gives a fixed-point answer

Possibly your code path has changed by as little as one character in a constant.

Log in to comment.

Answer by Youssef Khmou on 20 May 2013

hi, Maria,

If you want to display decimal ( floating point) numbers try :

 >>format long %  or format short

If you want fractional display try :

 >>format rat

and try :

 >>doc format


Thanks, i've tried this but didn't work.

If you just enter a number at the command line, how does it come out? For example if you entered


then does it come out in decimal or does it come out in fraction form?

I am trying to determine here whether you MATLAB is set to display fractions automatically or if instead the program is designed to display as fractions deliberately.

Yes, it show 2.345.. the thing is, that some values are showing as fraction and other values just in decimal form. I dont understand what happened! Look at this!

Re1 =


Nu1 =


h1 =


Re2 =


Nu2 =


Log in to comment.

Answer by Shashank Prasanna on 20 May 2013

>> format

Resets MATLAB display format to default.


Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!