Page 1 of 1
How to convert a float to integer?[Solved]
Posted: Sat Aug 21, 2010 7:10 pm
by BreakDS
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.
Re: How to convert a float to integer?
Posted: Sat Aug 21, 2010 10:37 pm
by ramarren
Common Lisp has a large number of
rounding functions for many rounding modes. What do you mean ROUND did not work?
Code: Select all
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?
Posted: Sun Aug 22, 2010 7:58 pm
by BreakDS
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"?
Re: How to convert a float to integer?
Posted: Sun Aug 22, 2010 11:17 pm
by ramarren
Re: How to convert a float to integer?
Posted: Mon Aug 23, 2010 6:21 pm
by BreakDS