ktbjx Posted October 25, 2018 Share Posted October 25, 2018 (edited) How do I remove leading Number after the decimal point from LINE elevation? (defun c:test (/ ss obj elev lay) (setq ss (ssget (list (cons 0 "LINE")))) (repeat (setq x (sslength ss)) (setq obj (ssname ss (setq x (- x 1)))) (setq elev (caddr (cdr (assoc 10 (entget obj))))) (setq lay (rtos elev 2 1)) (command "-layer" "m" lay "") (command "._change" obj "" "p" "la" lay "") ) (princ) ) Im so stupid, I know >.<" Edited October 25, 2018 by ktbjx Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 25, 2018 Share Posted October 25, 2018 (edited) So you want 0.1 to be .1 ? You convert to a string above code Lay = "0.1" , check 1st character if 0 then remove using "substr" and "strlen" function. Very easy. Edited October 25, 2018 by BIGAL Quote Link to comment Share on other sites More sharing options...
ktbjx Posted October 25, 2018 Author Share Posted October 25, 2018 5 minutes ago, BIGAL said: So you want 0.1 to be .1 ? You convert to a string above code Lay = "0.1" , check 1st character if 0 then remove using "substr" and "strlen" function. Very easy. im sorry, I made a mistake about my question, I want to remove all numbers after the decimal point. so for your example 0.1 would be 0 1.4000 will be 1 698.345 will be 698 just remove all numbers after decimal Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 25, 2018 Share Posted October 25, 2018 Rtos 2 0 will remove but be careful it will possibly round the answer else use rtos 2 1 then just remove the last two characters from the string lay using substr. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 25, 2018 Share Posted October 25, 2018 (edited) 6 hours ago, ktbjx said: I want to remove all numbers after the decimal point. so for your example 0.1 would be 0 1.4000 will be 1 698.345 will be 698 just remove all numbers after decimal 1.55 → 1 or 1.55 → 2 ? Edited October 25, 2018 by Lee Mac Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 25, 2018 Share Posted October 25, 2018 55 minutes ago, Lee Mac said: 1.55 → 1 or 1.55 → 2 ? I think he wants this algorithm of "rounding". Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 25, 2018 Share Posted October 25, 2018 (edited) In that case, change: (setq lay (rtos elev 2 1)) To: (setq lay (itoa (fix (+ 1e-8 elev)))) Edited October 25, 2018 by Lee Mac Quote Link to comment Share on other sites More sharing options...
Grrr Posted October 25, 2018 Share Posted October 25, 2018 Neat trick, Lee! (mapcar '(lambda (x) (fix (+ 1e-8 x))) '(2.1 2.9 3.14 0.15) ) >> (2 2 3 0) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 25, 2018 Share Posted October 25, 2018 (edited) 2 hours ago, Grrr said: Neat trick, Lee! (mapcar '(lambda (x) (fix (+ 1e-8 x))) '(2.1 2.9 3.14 0.15) ) >> (2 2 3 0) Thanks - of course, fix on its own would yield the same - _$ (mapcar 'fix '(2.1 2.9 3.14 0.15)) (2 2 3 0) But the inclusion of the 1e-8 'fuzz' accounts for rounding of doubles and avoids situations like this: _$ (fix (- 8.2 0.2)) 7 Though, when used in practice, one should really account for the possibility of negatives since: _$ (fix (+ -2 1e-8)) -1 And so, perhaps a better suggestion would be: (setq lay (itoa (fix ((if (minusp elev) - +) elev 1e-8)))) Edited October 25, 2018 by Lee Mac 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.