I thought the function 'round' might work, but it fails to do what I want.
Neither does 'coerce'. So I'm wondering is there any built-in function that works on this, say convert 2.1 to 2 and 2.9 to 3?
Thanks for answering a newbie's question.
How to convert a float to integer?[Solved]
How to convert a float to integer?[Solved]
Last edited by BreakDS on Mon Aug 23, 2010 6:21 pm, edited 1 time in total.
Re: How to convert a float to integer?
Common Lisp has a large number of rounding functions for many rounding modes. What do you mean ROUND did not work?
Do note that the second printed number is the secondary return value of the function, the remainder, and it is discarded in standard evaluation context.
Code: Select all
CL-USER> (round 2.1)
2
0.099999905
CL-USER> (round 2.9)
3
-0.099999905
Re: How to convert a float to integer?
Thx. I tried
(setf a (round 2.1))
and it works.
I was just confused by the TWO return value.
What should I do, if I want to capture these 2 value in 2 different variable by using "round"?
(setf a (round 2.1))
and it works.
I was just confused by the TWO return value.
What should I do, if I want to capture these 2 value in 2 different variable by using "round"?
Re: How to convert a float to integer?
There is a chapter on multiple value returning functions in Practical Common Lisp.
Re: How to convert a float to integer?
That's great. Thanks!
Ramarren wrote:There is a chapter on multiple value returning functions in Practical Common Lisp.