;
; Convert a floating-point number to a string of sign and at most 4 characters.
; Rounds the number so that 1.999 will come out as 2.00 , very small as 0.0 .
; numstring is written assuming that num is not too large or too small,
; i.e. num must be printable in 4 digits.
(define (cl:numstring num)
(let* ((numc (abs num)) (sign (if (< num 0) -1 1)) (exponent 0))
(if (< numc 1.0e-6)
"0.0"
(begin
(if (< numc 1.0)
(begin (while (< numc 100)
(set! numc (* numc 10))
(set! exponent (1- exponent)))
(set! numc (* (round numc) (expt 10 exponent))) )
(set! numc (* numc 1.0001)))
(if (< sign 0)
(string-append "-"
(substring (number->string numc) 0
(min 4 (string-length (number->string numc)))))
(substring (number->string numc) 0
(min 4 (string-length (number->string numc))))) ) ) ))