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

on 20 May 2013

### usman (view profile)

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

### Image Analyst (view profile)

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

### Maria Coronell (view profile)

on 20 May 2013

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

## Products

No products are associated with this question.

### 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.

### 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.

### usman (view profile)

on 3 Oct 2014

i have a question

### usman (view profile)

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?

#### Join the 15-year community celebration.

Play games and win prizes!

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