Ron Garret <rNOSPAMon@flownet.com> wrote:
+---------------
| Frode Vatvedt Fjeld <frodef@cs.uit.no> wrote:
| > Ron Garret <rNOSPAMon@flownet.com> writes:
| > > Because people get confused when they see $199/50 instead of $3.98.
| >
| > But isn't the presentation of something is separate from its internal
| > representation? If you present something using format and ~$, as would
| > be natural for dollar amounts, it doesn't matter if the representation
| > is float or rational. (format t "~$" 199/50) prints 3.98.
|
| Yes, I didn't know about the ~$ format directive.
| I'm still pondering the ramifications of allowing e.g. 1/3 of a dollar.
+---------------
The precision of ~$ only *defaults* to 2; you can specify another:
(format nil "~$" 8/3) ==> "2.67"
(format nil "~1$" 8/3) ==> "2.7"
(format nil "~4$" 8/3) ==> "2.6667"
Small "gotcha" to watch for: The ~$ format will [or, is allowed to]
coerce rationals to *single* floats, e.g.:
(format nil "~20$" 8/3) ==> "2.66666670000000000000"
(format nil "~20$" (coerce 8/3 'double-float))
==> "2.66666666666666650000"
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607