## Converting a fraction into a floating number

### Samuel Généreux (view profile)

on 30 Jan 2018 at 0:34
Latest activity Commented on by Walter Roberson

### Walter Roberson (view profile)

on 30 Jan 2018 at 15:46

Hi, I want to simply convert a fraction into a float. When I checked with the help, it seems really simple. To convert 2/5 into a float, it seems like I just need to type float(2/5). But, when I do that, I have for response :Error using float (line 46) The input argument to float was not a supported type. The only recognized input character vectors are 'single' and 'double'. The input type was 'double'. Can someone explain me that?

Walter Roberson

### Walter Roberson (view profile)

on 30 Jan 2018 at 14:56

John D'Errico

### John D'Errico (view profile)

on 30 Jan 2018 at 15:30

No. The examples given by Samuel are NOT consistent with the use of float as it is seen in the Simulink docs. However, they ARE consistent with the examples shown in the MuPAD documentation. That is why I talked about MuPAD. In fact, if I read the examples shown for the MuPAD float, we find very coincidentally these examples:

```float(17), float(PI/7 + I/4), float(4^(1/3) + sin(7))
```

As copied directly out of this link:

Walter Roberson

### Walter Roberson (view profile)

on 30 Jan 2018 at 15:46

John, you said that there is no MATLAB function called float, but there is a function by that name. It does not happen to be the function that the user wants, but some function with that name exists.

### John D'Errico (view profile)

on 30 Jan 2018 at 0:38

No. There is no need to use float.

```x = 2/5
x =
0.4
```
```whos x
Name      Size            Bytes  Class     Attributes
```
`    x         1x1                 8  double              `

x is automatically a floating point number, of class double.

Samuel Généreux

### Samuel Généreux (view profile)

on 30 Jan 2018 at 1:29

Ok thanks