Jump to content

Recommended Posts

Posted

This is my way to convert a float value into a float value with our required decimal points.Is this correct one or we have any alternative way?

 

CODE][/code]

 

(Setq a 1.57215)

(atof (rtos a 2 2))[

Posted

It is a good solution – AutoLISP doesn't have a built-in ROUND function.

 

Regarsd,

Posted

Nice solution, this is what I normally use:

 

;; Round (Lee Mac)
;; num  ~  number to be rounded.
;; dp   ~  decimal place to round at.

(defun Round (num dp / fac)
 (setq fac (expt 10. dp))

 (if (<= 0.5 (rem (setq num (* fac num)) 1))
   (/ (1+ (fix num)) fac)
   (/     (fix num)  fac)
 )
)

Posted

Nice catch!

 

;; Round (Lee Mac)
;; num  ~  number to be rounded.
;; dp   ~  decimal place to round at.

(defun Round (num dp / fac)
 (/
   (if (<= 0.5 (abs (rem (setq num (* (setq fac (expt 10. dp)) num)) 1)))
     ((if (minusp num) 1- 1+) (fix num))
     (fix num)
   )
   fac
 )
)

 

Thanks VovKa :)

Posted
(defun vk_RoundReal (InReal Precision)
 (/ (fix (- (* InReal (setq Precision (expt 10. Precision)))
     (/ (abs InReal) InReal -2.)
  )
    )
    Precision
 )
)

Posted

Superb VovKa :)

 

I love your way of making the half, if you add it, you could make the -2 positive :)

Posted
Superb VovKa :)

thanx

that was the day of no-ifs programming :)

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