View Full Version : Delimiting long numbers
shadygrafix
2006-06-22, 02:24 AM
Is there a way to delimit with commas numbers returned from a lisp routine. I have a routine that will calculate the volume in Gallons of a basin. Basins are very large (we are talking water treatment and storage, not sinks) and the engineer wants to delimit the volume with commas. Here's the lisp in case anyone needs something like it or would like to find the answer. And yes it plots the information to a table not a made table from lines and text.
CAB2k
2006-06-22, 03:51 AM
Try this:
;; By CAB 07/21/2006
;; (addComma "10987654321.0123")
;; "10,987,654,321.0123"
(defun addcomma (txt / strl next newl idx)
(setq strl (reverse (vl-string->list txt)))
(if (vl-position 46 strl)
(while
(progn
(setq newl (cons (setq next (car strl)) newl)
strl (cdr strl))
(/= next 46)
)
)
)
(setq idx -1)
(while (setq next (car strl))
(if (= (setq idx (1+ idx)) 3)
(setq newl (cons 44 newl)
idx 0
)
)
(setq newl (cons next newl)
strl (cdr strl)
)
)
(vl-list->string newl)
)
shadygrafix
2006-06-22, 09:04 PM
thanks works like a charm and now I don't have to spend 15min putting in commas :)
Thanks again.
CAB2k
2006-06-23, 01:40 AM
You're quite welcome.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.