Number Formatting

Number Formatting

F.Camargo
Advisor Advisor
1,736 Views
4 Replies
Message 1 of 5

Number Formatting

F.Camargo
Advisor
Advisor

Hi guys

 

I'm trying to change the format of the number.
e.g 1478,497m to 1.478,497m
or 1478497,585m to 1.478.497,585m

 

I've already put the comma. (thanks to ymg sub rotine).
I'd like to put the period.

 

This is a very old lisp.

(defun C:LP(/ PNT1 P1X P1Y STDY DY COORDN COORDE PTXT)

(vl-load-com)


;;; Settings Section Adjust These Values ;

(setq 
decsymb "," ; Decimal Symbol "," or "." ;
)


(setq PNT1 (getpoint
"\nPick coordinate point: "))
(setq P1X (car pnt1)) ;x coord
(setq P1Y (cadr pnt1)) ;y coord
(setq STDX (rd (rtos P1X 2 3)))
(setq STDY (rd (rtos P1Y 2 3)))
(setq COORDN (strcat "N " STDY "m"))
(setq COORDE (strcat "E " STDX "m"))
(setq PTXT (getpoint
"\nPick text location: "))
(command "LEADER" PNT1 PTXT "" COORDN COORDE "")
(princ)
)

;; rd function to replace decimal separator in string ;
;; Variable decsymb is defined outside the routine ;
;by ymg
(defun rd (str) (vl-string-subst decsymb "." str))

 

 

Thanks in advance

Fabrício

0 Likes
Accepted solutions (1)
1,737 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

HERE on theswamp.org are many examples.

 

To swap commas with dots -if needed- use the translate function:

 

(vl-string-translate ",." ".," "yournumber")

Message 3 of 5

F.Camargo
Advisor
Advisor

@ВeekeeCZ wrote:

HERE on theswamp.org are many examples.

 

To swap commas with dots -if needed- use the translate function:

 

(vl-string-translate ",." ".," "yournumber")


Hi

 

I see the link my friend.

Do I have to add a new sub rotina in the code to put 1.000 period separator?

 

I have doubts because I put a sub rotine to substitute "." to ",". Is it gonna change?

 

I'm newbie. Smiley Frustrated

 

Thanks

Fabrício

 

 

0 Likes
Message 4 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

 

 

(vl-load-com)

(defun C:LP(/ rtoc PNT1 P1X P1Y STDY DY COORDN COORDE PTXT)

  ;; Lee Mac
  ;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/1-000-comma-separator/m-p/5015892#M322341
  
  (defun rtoc ( n p / foo d l ) ;; modified for metric
    (defun foo ( l n )
      (if (or (not (cadr l)) (= 46 (cadr l)))
	l
	(if (zerop (rem n 3))
	  (vl-list* (car l) 44 (foo (cdr l) (1+ n)))
	  (cons (car l) (foo (cdr l) (1+ n))))))
    (setq d (getvar 'dimzin))
    (setvar 'dimzin 0)
    (setq l (vl-string->list (rtos (abs n) 2 p)))
    (setvar 'dimzin d)
    (vl-string-translate ",." ".," (vl-list->string
      (append (if (minusp n) '(45))
	      (foo l (- 3 (rem (fix (/ (log (abs n)) (log 10))) 3)))))))

  ; ----------------
  
  (setq PNT1 (getpoint "\nPick coordinate point: "))
  (setq P1X (car pnt1)) ;x coord
  (setq P1Y (cadr pnt1)) ;y coord
  (setq STDX (rtoc P1X 3))
  (setq STDY (rtoc P1Y 3))
  (setq COORDN (strcat "N " STDY "m"))
  (setq COORDE (strcat "E " STDX "m"))
  (setq PTXT (getpoint "\nPick text location: "))
  (command "LEADER" PNT1 PTXT "" COORDN COORDE "")
  (princ)
  )

 

 

Message 5 of 5

F.Camargo
Advisor
Advisor

Thank you for your help my friend. Smiley Happy

 

You helped me a lot.

 

Regards

Fabrício

0 Likes