This seems like it should be obvious, but how do you convert Clojure's ratio type to a percentage?
(format "%3s" (/ 1 2))
;; "1/2"
(format "%3f" (/ 1 2))
;; Throws an error
You can always convert to Float
:
(format "%3f" (float (/ 1 2)))
cl-format
, which is derived from Common Lisp's format
, is more flexible than Clojure's Java-based format
in some situations:
(require 'clojure.pprint)
(clojure.pprint/cl-format nil "~f" (/ 1 2)) ;=> "0.5"
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