How to pass a value to a function that control how many number in decimal point to print.
I can do with $ or f, e.g
(format t "~,3f" 3.141592)
(format t "~2$" 3.141592)
But how to do something like this
(defun control-format (x)
(format nil "~,xf" 3.141592))
So we can pass any number as argument to control-format to control how many decimal number we want.
Thanks.
Use v instead of a literal number:
* (dotimes (i 8)
(format t "~,vf~%" i pi))
3.
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
NIL
*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With