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

#1 NecroWinter  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 320
  • 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  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 145
  • View blog
  • 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)) ))


Was This Post Helpful? 2
  • +
  • -

#3 NecroWinter  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 320
  • Joined: 21-October 11

Re: convert a fraction to a floating point number

Posted 17 January 2013 - 01:08 PM

View PostTayacan, 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!
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

Re: convert a fraction to a floating point number

Posted 17 January 2013 - 01:14 PM

View PostNecroWinter, 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.
Was This Post Helpful? 2
  • +
  • -

#5 Tayacan  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: convert a fraction to a floating point number

Posted 17 January 2013 - 01:18 PM

View PostNecroWinter, 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

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1