Files
lisplings/solutions/09_strings/str5.lisp
T

18 lines
594 B
Common Lisp

;;; STRINGS 5: NUMBERS IN FORMAT (solution)
(defun price-tag (n)
(format nil "~:d widgets" n))
(defun fixed (label n)
(format nil "~a is about ~,2f" label n))
;;; ------------------------------------------------------------------
;;; Checks. Read them - they tell you what to aim for - but leave
;;; them unchanged.
;;; ------------------------------------------------------------------
(check-equal "1,234,567 widgets" (price-tag 1234567))
(check-equal "7 widgets" (price-tag 7))
(check-equal "pi is about 3.14" (fixed "pi" pi))
(check-equal "e is about 2.72" (fixed "e" 2.718281828))