Author Topic: How to specify Decimal precision in Table generate?  (Read 2388 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How to specify Decimal precision in Table generate?
« on: December 12, 2010, 11:23:45 AM »
In this subroutine
How to force precision to be 3 digits?
Code: [Select]
(defun Gen_Table ()

  (setq TblPnt (vlax-3d-point (getpoint "\nUpper left table insertion point: ")))
  (setq Gen:Table (vla-AddTable
   mSp
   TblPnt
   (1+ cntr)
   4
   (* 4 (getvar "DIMTXT"))
   (* 14 (getvar "DIMTXT"))
 ))
  (setq T:X  2)
  (setq T:Y  0)
  (setq T:R  0)

  (vla-put-layer Gen:Table "EC-TEXT-22-SCALE")
  (vla-put-StyleName Gen:Table "STANDARD")
  (vla-SetAlignment Gen:Table acDataRow acMiddleCenter)
  (vla-setText Gen:Table 0 0 "Coordinate")
  (vla-setText Gen:Table 1 0 "Point No")
  (vla-setText Gen:Table 1 1 "X")
  (vla-setText Gen:Table 1 2 "Y")
  (vla-setText Gen:Table 1 3 "Remarks")
  
  (foreach i P2LST
    (vla-setText Gen:Table T:X 0 (nth T:Y P2LstN))
    (vla-setText Gen:Table T:X 1 (nth T:Y P2LstX))
    (vla-setText Gen:Table T:X 2 (nth T:Y P2LstY))
    (setq T:X (1+ T:X))
    (setq T:Y (1+ T:Y)))
)

Robert98

  • Guest
Re: How to specify Decimal precision in Table generate?
« Reply #1 on: December 12, 2010, 03:49:00 PM »
Hi Hassan

This is Dear member gile's solution at this post:

http://autolisp-exchange.com/Forums/Forum2/F2T35P1.htm

but I think you can first convert your numbers to strings and then use of (RTOS XXXX 2 2) method 

Here dear giles routines : ;-)

;;; Rounds a number to the closest value according to precision argument
;;; (round pi 0.01) -> 3.14
;;; (round pi 1e-5) -> 3.14159
;;; (round 5456.50 1.0) -> 5457.0
;;; (round 5456.50 100.0) -> 5500.0
Code: [Select]

(defun round (num prec)
  (if (< 0 prec)
    (* prec
       (fix (if    (minusp num)
          (- (/ num prec) 0.5)
          (+ (/ num prec) 0.5)
        )
       )
    )
    num
  )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to specify Decimal precision in Table generate?
« Reply #2 on: December 12, 2010, 05:27:21 PM »
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.