# convert a fraction to a floating point number

Page 1 of 1

## 4 Replies - 9353 Views - Last Post: 17 January 2013 - 01:18 PM

### #1 NecroWinter

• D.I.C Regular

Reputation: 38
• Posts: 329
• Joined: 21-October 11

# convert a fraction to a floating point number

Posted 17 January 2013 - 12:10 PM

ive been looking around a bit, and this is like my second day with lisp, so a lot of the solutions im finding are way over my head and seem to be solving bigger issues that what I present.

I have the following code that I came up with, it simply converts Fahrenheit to Celsius. The problem is, ill get a fraction, when I need to return a floating point number rounded to the nearest degree
```(defun convert (x)
(*(- x 32)(/ 5 9)) )
```

Is This A Good Question/Topic? 0

## Replies To: convert a fraction to a floating point number

### #2 Tayacan

• D.I.C Regular

Reputation: 145
• Posts: 275
• Joined: 18-January 11

## Re: convert a fraction to a floating point number

Posted 17 January 2013 - 12:44 PM

Here ya go.

Or in other words:

```(defun convert (x)
(float (*(- x 32) (/ 5 9)) ))

```

### #3 NecroWinter

• D.I.C Regular

Reputation: 38
• Posts: 329
• Joined: 21-October 11

## Re: convert a fraction to a floating point number

Posted 17 January 2013 - 01:08 PM

Tayacan, on 17 January 2013 - 12:44 PM, said:

Here ya go.

Or in other words:

```(defun convert (x)
(float (*(- x 32) (/ 5 9)) ))

```

I think part of the confusion for me was due to the fact that I was told this is done with placing a "." at the end of a number, I tried every combination I could think of and I usually ended up with the same answer.

I didnt even know that you can do datatypes like this, but then again, its like my second day and everything ive done so far has been on a chalk board
in any event, thank you!

### #4 sepp2k

• D.I.C Lover

Reputation: 2307
• Posts: 3,568
• Joined: 21-June 11

## Re: convert a fraction to a floating point number

Posted 17 January 2013 - 01:14 PM

NecroWinter, on 17 January 2013 - 08:10 PM, said:

I have the following code that I came up with, it simply converts Fahrenheit to Celsius. The problem is, ill get a fraction, when I need to return a floating point number rounded to the nearest degree

You can use the round function to get to the nearest degree, but the result of that will be an exact integer, not a floating point number. You can convert the result of an integer to a float if you want, but I don't really understand why you need to if it's rounded to an integer amount anyway.

### #5 Tayacan

• D.I.C Regular

Reputation: 145
• Posts: 275
• Joined: 18-January 11

## Re: convert a fraction to a floating point number

Posted 17 January 2013 - 01:18 PM

NecroWinter, on 17 January 2013 - 08:08 PM, said:

I didnt even know that you can do datatypes like this, but then again, its like my second day and everything ive done so far has been on a chalk board

I can thoroughly recommend getting an interpreter and typing stuff in to see what happens.

e: Actually, here ya go.

This post has been edited by Tayacan: 17 January 2013 - 01:19 PM