You can define a function that will be called with a tilde-slash, which most of the other answers have already performed, but to get a result similar to ~ F, but with the entered commas of characters and replacing the decimal point, I think itβs best to call the result created by ~ F, and then modify it and write to a string. Here's how to do this using the insert-comma utility, which adds a comma character at regular intervals to the line. Here's the directive function:
(defun print-float (stream arg colonp atp &optional (point-char
Here are some examples:
(progn ;; with @ (for sign) and : (for grouping) (format t "~',' .2@ :/print-float/ ~%" 12345.6789) ;=> +1.23.45,679 ;; with no @ (no sign) and : (for grouping) (format t "~'.'_3:/print-float/ ~%" 12345.678) ;=> 12_345.678 ;; no @ (but sign, since negative) and : (for grouping) (format t "~'.'_3:/print-float/ ~%" -12345.678) ;=> -12_345.678 ;; no @ (no sign) and no : (no grouping) (format t "~'.' _3@ /print-float/ ~%" 12345.678)) ;=> +12345.678 (no :)
Here are some examples from coredump-answer that actually helped me catch the error with negative numbers:
CL-USER> (loop for i in '(1034.34 -223.12 -10.0 10.0 14 324 1020231) do (format t "~','.:/print-float/~%" i)) 1.034,34 -223,12 -10,0 10,0 14,0 324,0 1.020.231,0 NIL
Here 's a comma insert , with some examples:
(defun inject-comma (string comma-char comma-interval) (let* ((len (length string)) (offset (mod len comma-interval))) (with-output-to-string (out) (write-string string out :start 0 :end offset) (do ((i offset (+ i comma-interval))) ((>= i len)) (unless (zerop i) (write-char comma-char out)) (write-string string out :start i :end (+ i comma-interval))))))
(inject-comma "1234567" #\, 3) ;;=> "1,234,567" (inject-comma "1234567" #\. 2) ;;=> "1.23.45.67"