ALLI Posted June 22, 2017 Share Posted June 22, 2017 I am hoping for some help as to why my LISP wont work, I have a heap of text saying things like 29.999, 27.999 etc. which I need changed to 30.00, 28.00 etc. I am trying to use the following but cant get it to work. See lisp below ;ROUND TO 5 (defun c:Rnd5(/ a n index b d c num newnum d1 b1 len last) (graphscr) (prompt "Select numbers to be rounded") (terpri) (setq a(ssget)) (setq n (sslength a)) (setq index 0) (repeat n (setq na (ssname a index)) (setq b (entget na)) (setq d (assoc 1 b)) (setq c (cdr d)) ; text item (setq num (atof c));converts it to number (setq num (* 2 num));doubles it (setq num (rtos num 2 2));rounds off to 2 places (setq num (atof num));converts it to number (setq num (/ num 2));divides by 2 (setq newnum (rtos num 2 3));rounds off (setq len (strlen newnum)) (setq last (substr newnum len)) (if (= last "0") (setq newnum (rtos num 2 2))) (setq d1 (cons(car d)newnum)) (setq b1(subst d1 d b)) (entmod b1) (setq index (+ 1 index)) (print) ) (defun round (num near) (* (fix (/ (+ num (/ near 2.0)) near)) near) ) Quote Link to comment Share on other sites More sharing options...
rlx Posted June 22, 2017 Share Posted June 22, 2017 (edited) (fix (+ num 0.5)) gr.R. https://www.theswamp.org/index.php?topic=44487.0 see Master Lee's round up function too.. Edited June 22, 2017 by rlx 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.