float to string

float to string

Anonymous
Not applicable
2,925 Views
3 Replies
Message 1 of 4

float to string

Anonymous
Not applicable

Hi guys,

 

i am looking for a AutoLISP command which converts a float to a string.

 

Pls help!

0 Likes
2,926 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

A float is a real. So (rtos) function.

 

> (setq fl (float 2))
> (rtos fl 2 2)
2.00

>(rtos fl 2 0)
2

Watch DIMZIN sysvar for tailing zeros.

 

See HERE about the conversion functions.

0 Likes
Message 3 of 4

Anonymous
Not applicable
rtos works

Can set the precision if required

eg. (rtos pi 2 2 ) returns "3.14"

(rtos pi 2 3 ) returns "3.142"
0 Likes
Message 4 of 4

pbejse
Mentor
Mentor

@Anonymous wrote:

 

i am looking for a AutoLISP command which converts a float to a string.

 

Pls help!


 

Hmmmmmn

 

This?

 

(defun _floattostring  (f)
      (defun replace-n  (new n lst /)
            (mapcar '(lambda (a)
                           (if (= (setq n (1- n)) -1)
                                 new
                                 a))
                    lst))
(if (eq (Strcase f t)  "float")
    (progn
      (setq n -1
            f (vl-string->list f))
      (setq strin
                 (mapcar
                       (function
                             (lambda (a b c)
                                   (setq d    nil
                                         n    (1+ n)
                                         symb (if (minusp a)
                                                    1-
                                                    1+))
                                   (repeat (abs a)
                                         (setq d (cons
                                                       (setq f    (replace-n
                                                                        (setq b (symb b))
                                                                        n
                                                                        f))
                                                       d)))
                                   )
                             )
                       '(13 8 3 8 -6)
                       f
                       '(115 116 114 105 110))
            )
      (textscr)
      (foreach
             itm
             (cons '(102 108 111 97 116)
                   (append (apply 'append (mapcar 'reverse strin))
                           '((115 116 114 105 110 103))))
            (print (vl-list->string itm))
            (princ)
            )
      (princ "<<--- TADA!! ")
      
      )
    (alert(Strcat "\nHey!! I said float not " (Strcase f )))
      )
    (princ)
    )

 

(_floattostring "float")

 

HTH

 

"All work and no play makes pBe a dumb boy"

 

😄