Jump to content

Help my LISP isnt working! - Rounding 29.99 to 30.00


ALLI

Recommended Posts

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)
)
 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...