Visual LISP, AutoLISP and General Customization

## Visual LISP, AutoLISP and General Customization

Mentor
Posts: 208
Registered: ‎06-08-2010
Message 1 of 7 (400 Views)

# bassic maths rounding off to full figure autolisp

400 Views, 6 Replies
04-25-2012 06:14 AM

I need to know how to do a particular equation-using lisp

Her goes I have 6000mm divided by distances of 610mm leaves me with 9.836065574 rectangular arrays the amount rectangular arrays has to be a full figure how can I round this of to the next full figure of 10.

The amount of rectangular arrays will vary pending on how long I want my wall to be so as to say the 6000mm is hardly ever the same. Unlike the 610mm which is a value set by the industry (610mm is the distance allowed in-between beams AKA: always and without exception the same)

Please use plain text.
*Expert Elite*
Posts: 2,346
Registered: ‎11-24-2009
Message 2 of 7 (399 Views)

# Re: bassic maths rounding off to full figure autolisp

04-25-2012 06:19 AM in reply to: The_Caddie

(fix (+ 9.836065574
(/ 9.836065574 (abs 9.836065574) 2.0)
)
)

Please use plain text.
Mentor
Posts: 208
Registered: ‎06-08-2010
Message 3 of 7 (394 Views)

# Re: bassic maths rounding off to full figure autolisp

04-25-2012 06:31 AM in reply to: pbejse

this works fine i should leave it at that however could you give us a quick runthrough on what your example is doing so i may understand rather then just accept...

thanks-

Please use plain text.
*Expert Elite*
Posts: 2,346
Registered: ‎11-24-2009
Message 4 of 7 (387 Views)

# Re: bassic maths rounding off to full figure autolisp

04-25-2012 06:59 AM in reply to: The_Caddie

The_Caddie wrote:

could you give us a quick runthrough on what your example is doing so i may understand rather then just accept...

thanks-

The fix function will round the value to nearest smaller integer.

(fix 2.5)  --> 2

(fix 2.75) - > 2

to avoid that. what we did is throw in a factor that determines the decimal value is above or belowhalf of 1.0

( / 2.75 2.75 2.0) <-- same as  ( / 2.75 2.75)  ( / 1.0 2.0)

0.5

add to original number

(+ 2.75 0.5)

3.25

(fix 3.25)

3 <-- still the nearest smaller integer

HTH

Please use plain text.
*Expert Elite*
Posts: 4,807
Registered: ‎09-13-2004
Message 5 of 7 (385 Views)

# Re: bassic maths rounding off to full figure autolisp

04-25-2012 07:00 AM in reply to: The_Caddie

The_Caddie wrote:

....

Her goes I have 6000mm divided by distances of 610mm leaves me with 9.836065574 rectangular arrays the amount rectangular arrays has to be a full figure how can I round this of to the next full figure of 10.

....the 610mm which is a value set by the industry (610mm is the distance allowed in-between beams AKA: always and without exception the same)

Put "round" or "rounding" or "round up" into the Search window, and you will find many examples of how to do this, with varying degrees of explanation, rounding to the nearest integer value or to the nearest multiple of some value such as your 610, some that round to the nearest value in whichever direction is closer and some that only round up, and other differences.

Kent Cooper
Please use plain text.
Mentor
Posts: 208
Registered: ‎06-08-2010
Message 6 of 7 (342 Views)

# Re: bassic maths rounding off to full figure autolisp

04-26-2012 11:24 PM in reply to: pbejse

I’m sorry I have to com back on this because its been pointed out through my testing of the lisp that my situation is dependant on a factor of whether the rounding of is over or below x.5

Anything below x.5 (example 10.342) should round down to the nearest and anything above x.5 should (example 67.567round up. As for items that fall exactly on x.5 (example 2978.5) they should round down also

(X representing any number before the decimal place).

Please use plain text.
*Expert Elite*
Posts: 2,346
Registered: ‎11-24-2009
Message 7 of 7 (338 Views)

# Re: bassic maths rounding off to full figure autolisp

04-26-2012 11:53 PM in reply to: The_Caddie

The_Caddie wrote:

Anything below x.5 (example 10.342) should round down to the nearest and anything above x.5 should (example 67.567round up. As for items that fall exactly on x.5 (example 2978.5) they should round down also

Quick fix

(if (eq (rem num (fix num)) 0.5) (fix num)
(fix (+ num
(/ num (abs num) 2.0)
)
)
)

Please use plain text.

### You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

### Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Recently Solved

• ## initget and getpoint

### Browse Forums

AutoCAD Customization