## How can I change it to display decimal number?

### Maria Coronell (view profile)

on 20 May 2013
Latest activity Commented on by Steven Lord

on 13 Sep 2017

### Walter Roberson (view profile)

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?

Walter Roberson

### Walter Roberson (view profile)

on 29 Nov 2016

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

Kantaphon Meechart

### Kantaphon Meechart (view profile)

on 21 Apr 2017

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

Walter Roberson

on 21 Apr 2017

### Walter Roberson (view profile)

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,

```double(Nu2)
```

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

Maria Coronell

### Maria Coronell (view profile)

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

### Walter Roberson (view profile)

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.

Steven Lord

### Steven Lord (view profile)

on 13 Sep 2017

Note that if your symbolic expression contains a symbolic variable, using double won't work.

```syms x
y = sqrt(2)*x
double(y) % throws an error
```

In that case you could use vpa to approximate the symbolic expression.

```syms x
y = sqrt(2)*x
vpa(y)
```

### Youssef Khmou (view profile)

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

### Maria Coronell (view profile)

on 20 May 2013

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

Walter Roberson

### Walter Roberson (view profile)

on 20 May 2013

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

```2.345
```

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

### Maria Coronell (view profile)

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 =

`    7.489184809171960e+004`

Nu1 =

`    3.473689192970496e+002`

h1 =

`    1.047513915597188e+004`

Re2 =

1422543653887999360776996931534847612609041143314926486102736896/18415266480134414561195254170806684536779318144366885369925

Nu2 =

(70353137442027663*18415266480134414561195254170806684536779318144366885369925^(9/20)*1422543653887999360776996931534847612609041143314926486102736896^(11/20))/2073374681446543372437154885376994391455329959260590683959033514499768320000

### Shashank Prasanna (view profile)

on 20 May 2013

```>> format
```

Resets MATLAB display format to default.

Shima Khatiri

### Shima Khatiri (view profile)

on 13 Sep 2017

It's not a solution to this problem.

Steven Lord

### Steven Lord (view profile)

on 13 Sep 2017

That will help if you want to change how numeric data is displayed. But it will not change how symbolic expressions are displayed. Walter's answer (with the additional point I added) is a solution and I have just marked it Accepted.