Author Topic: Round to nearest foot?  (Read 3042 times)

0 Members and 1 Guest are viewing this topic.

KewlToyZ

  • Guest
Round to nearest foot?
« on: October 23, 2008, 01:50:27 PM »
(setq x 17.5)
(setq fmtval (rtos x 4 2))     ; Mode 4 = architectural
(princ (strcat str fmtval))    ; displays  Value formatted as 1'-5 1/2"

    (setvar "unitmode" 0)
    (setvar "LUPREC" 0)
    (setvar "DIMRND" 1)
    (setvar "DIMDEC" 0)

How do I get rtos to round to the nearest foot for output?
Is this a variable I am missing?
« Last Edit: October 23, 2008, 01:55:04 PM by KewlToyZ »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Round to nearest foot?
« Reply #1 on: October 23, 2008, 02:36:33 PM »
Use Kerrys function
Code: [Select]
;;* kdub:roundNearest (numVal roundTo Mode displayPrecision)
;; Round a numeric positive number to the NEAREST 'rounded' number
;; and format to n digits
;; kwb@theSwamp 20070814
;;  20081023 CAB added Mode
(DEFUN kdub:roundNearest (numVal roundTo Mode displayPrecision / remNum)
    (SETQ remNum (REM numVal roundTo))
    (RTOS (IF (>= (* 2 remNum) roundTo)
              (+ numVal (- roundTo remNum))
              (- numVal remNum)
          )
          Mode
          displayPrecision
    )
)

Code: [Select]
(kdub:roundNearest 17.5 12 4 0)
"1'-0\""
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

KewlToyZ

  • Guest
Re: Round to nearest foot?
« Reply #2 on: October 23, 2008, 06:14:41 PM »
Thanks CAB   8-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Round to nearest foot?
« Reply #3 on: October 23, 2008, 07:09:52 PM »
Glad to help & thanks to Kerry. 8-)

http://www.theswamp.org/index.php?topic=18695.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Round to nearest foot?
« Reply #4 on: October 23, 2008, 07:55:01 PM »
Nice adaptation Alan .. I tend to ignore that some of the world still uses inches and feet. ( though I still thing in both occasionally for non technical stuff ... :) )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Round to nearest foot?
« Reply #5 on: October 23, 2008, 09:01:18 PM »
All of My World uses feet & inched. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

KewlToyZ

  • Guest
Re: Round to nearest foot?
« Reply #6 on: October 28, 2008, 04:33:59 PM »
I ended up adapting it differently for the setup I was doing using the files attached.
Mainly I was trying to make something generic for creating engineering spaces.
When I get time I was thinking of adding a block insert to create a small Engineering Space numeric bubble and a routine at the end to autoincrement the attribute tag so notes can be assigned.
Its still a pretty hokey adaption of what the guys on the swamp here made but it works. :wink: