This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

How to convert a float to integer?[Solved]

5 posts · 5812 views

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.

Last edited by BreakDS on , 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?
CL-USER> (round 2.1)
2
0.099999905
CL-USER> (round 2.9)
3
-0.099999905
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.

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"?