The Tostring function, prepared by MP in
https://www.theswamp.org/index.php?topic=4814.0 has been very helpful for me in the preparation of lines of text for saving files containing lists with variable values to be recovered for later uses.
However, I found that saving real numbers of type 3.0 or 3. with a decimal part equal to 0 always resulted in a string "3"; this behavior is due to the dimzin system variable, which automatically suppresses the zeros, so I made a small change to the function itself.
(defun ToString
(x
/ typex
) ;; convert item to a string, if x is a real use
;; the highest possible precision, if x is a
;; string double quote it, if x is a list process
;; each item in the list appropriatel, otherwise
;; just hammer item with vl-princ-to-string
;; (ToString 1.0 )
(cond ;; it's a string, return it double quoted ;; it's a real, with decimal
((and (eq 'real typex
) (= (- x
(fix x
)) 0.0)); reali con parte decimale nulla (setvar 'dimzin
1); variabile sistema dimzin a 1 consente di non sopprimere gli zeri finali nelle quote decimali (setq res$
(rtos x
2 1)) ;_ numeri reali coincidenti con interi trasformati in stringhe con un solo decimale res$)
;; it's a real, covert to the highest possible
;; resolution string equivalent
2
1
15)))
;; it's a list
;; it's a normal list
;; it's a dotted pair
;; hammer down on everything else