Author Topic: Having some rounding issues  (Read 1358 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Having some rounding issues
« on: January 18, 2017, 11:56:04 AM »
I do not know if I did something awhile ago to get this not work... (I am good at that). But I am having some rounding issues. The routine is suppose to override the dim text from <> to (X SPACES @ X' = <>').

For example if the dim is 63'. The label now shows it to be 6 Spaces @ 9'. 6x9=54.

But in the same drawing on a different dimension. The dim is 162'. The Label shows 18 Spaces @ 9' = 162'. Which is right.

The Routine is within a macro.

^C^C-dimstyle;V;L80;DIMZIN;8;-dimstyle;apply;all;;(load "SPCT");SPCT;

Any ideas?

Code: [Select]
(defun C:SPCT
  (/ ename obj dim div total fract)
  (setq ename (car (entsel "\nSelect dimension: ")))
  (setq obj (vlax-ename->vla-object ename))
  (setq dim (vla-get-measurement obj))
  (if (not def)
    (setq def 1))
  (setq div (getdist (strcat "\nDivide into <" (rtos def) ">: ")))
  (if (not div)
    (setq div def)
    (setq def div))

  (setq total (/ dim div))
  (setq fract (- total (fix total)))

  (vla-put-textoverride
    obj
    (strcat (itoa (fix total))
    " SPACES @ "
    (rtos div)
             "'"
             " = <>"
       ))
  (princ))

Thanks for the help!
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Having some rounding issues
« Reply #1 on: January 18, 2017, 12:22:02 PM »
Are you sure your dimension is exactly 63'? (setq total (fix (/ 62.999999 9))) = 6
« Last Edit: January 18, 2017, 12:31:08 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Having some rounding issues
« Reply #2 on: January 18, 2017, 12:44:52 PM »
I would suggest changing all occurrences of:
Code: [Select]
(fix total)to:
Code: [Select]
(fix (+ 1e-8 total))

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Having some rounding issues
« Reply #3 on: January 18, 2017, 01:00:59 PM »
Ron and Lee,
Thanks for the pointers. That's what it was missing. Thank you guys again!
Civil3D 2020