Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

numeric format, digital grouping, thousands seperator

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
kbarnettza
363 Views, 4 Replies

numeric format, digital grouping, thousands seperator

Is there an autolisp function to format the text string conversion of a real?

I need a thousand seperator - space between each group of 3 values left of the decimal.

thx ..

 

4 REPLIES 4
Message 2 of 5
Ajilal.Vijayan
in reply to: kbarnettza

Modified the function found in here

 

(defun space (n p / a b m i lst)
(setq dz (getvar 'dimzin))
(setvar 'Dimzin 0)  
(setq str (rtos (abs n) 2 p))
(setvar 'Dimzin dz)  
	(setq a	(vl-filename-base str)
	      b	(substr str (1+ (strlen a)))     
	      m	(vl-string->list a)
	      i	(length m) lst nil)
	(while (>= i 3)
	(setq lst (append (list 32
		   (nth (- i 3) m)
	           (nth (- i 2) m)
	           (nth (1- i) m)) lst ) i ( - i 3)) lst )
	(strcat (if (minusp n) "-" "")(substr str 1 i)  
		(vl-list->string (if (zerop i) (cdr lst) lst))
		b))

 

Command: (space 123456789 3)
"123 456 789.000"

 

 

Message 3 of 5
kbarnettza
in reply to: Ajilal.Vijayan

Excellent! Thank You!

Message 4 of 5
pbejse
in reply to: Ajilal.Vijayan


@Ajilal.Vijayan wrote:

Modified the function found in here....

 

 


No wonder the coding looks familiar Smiley Wink

Message 5 of 5
Gary_J_Orr
in reply to: pbejse


@pbejse wrote:

@Ajilal.Vijayan wrote:

Modified the function found in here....

 

 


No wonder the coding looks familiar Smiley Wink


Well heck *pbejse* a simple modification to your original and no one will have to create any other versions of your original and you will live forever:

;pbejse - modified
;(DelimTxt 123456789 3 " ")
;(DelimTxt 123456789 3 ",")
;(DelimTxt 123456789 3 " : ")
(defun DelimTxt (n p d / dz dl a b m i lst)
  (setq dl (vl-string->list d))
  (setq dz (getvar 'dimzin))
  (setvar 'Dimzin 0)
  (setq str (rtos (abs n) 2 p))
  (setvar 'Dimzin dz)
  (setq
    a	(vl-filename-base str)
    b	(substr str (1+ (strlen a)))
    m	(vl-string->list a)
    i	(length m)
    lst nil
    );setq
  (while (>= i 3)
    (setq
      lst (append
	    dl
	    (list 
	      (nth (- i 3) m)
	      (nth (- i 2) m)
	      (nth (1- i) m)
	      );list
	    lst);append
      i (- i 3)
      );setq
    lst
    );while
  (strcat (if (minusp n) "-" "")
	  (substr str 1 i)
	  (vl-list->string (if (zerop i) (member (nth (length dl) lst) lst) lst))
	  b);strcat
  );DelimTxt

 <Grins>

-Gary

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost