MATLAB Answers

Maria Coronell

How can I change it to display decimal number?

Asked by Maria Coronell
on 20 May 2013
Latest activity Answered by usman
on 3 Oct 2014

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?


Image Analyst
on 20 May 2013

Please give examples. Do you mean like it's showing 1/4 and you want it to show 0.250000, or showing 5/2 and you want it so show 2.50000?

Maria Coronell
on 20 May 2013

thats what im saying, I want decimal numbers for my answers. Thanks


No products are associated with this question.

5 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.)


Maria Coronell
on 21 May 2013

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.

Walter Roberson
on 21 May 2013

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.

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


Maria Coronell
on 20 May 2013

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

Walter Roberson
on 20 May 2013

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.

Maria Coronell
on 21 May 2013

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 =


Answer by Shashank Prasanna
on 20 May 2013
>> format

Resets MATLAB display format to default.


Answer by usman
on 3 Oct 2014

i have a question


Answer by usman
on 3 Oct 2014

n = 5371 x = ceil(sqrt(n)) i = 1 y = √(x0² - n) if (y is an integer and least significant digit of x are 0, 1, 4 or 9) p = x + y q = x- y end process else x0 = x1 + i //[till y is an integer]

how i convert "bold" line in matlab?


Discover MakerZone

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

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!