From: Robert Monfera
Subject: Formatting: separating commas for non-decimals
Date:
Message-ID: <382DB6FF.907F2FEC@fisec.com>
Hello,
I needed to format a number such that there are separating commas at
every third digit (dollars), and two decimals for the cents:
3,352,194.82
I haven't found any directive for this one, so I glued it together with
the help of FLOOR. I looked at the CLHS and CLtL2 - I feel I must have
overlooked something.
Thanks,
Robert
On Sat, 13 Nov 1999 14:07:43 -0500, Robert Monfera <·······@fisec.com> wrote:
> I needed to format a number such that there are separating commas at
> every third digit (dollars), and two decimals for the cents:
> 3,352,194.82
Sounds like a pretty typical problem. I had the same one, and was similarly
surprised that Lisp didn't seem to have any built-in way of doing this.
> I haven't found any directive for this one, so I glued it together with
> the help of FLOOR. I looked at the CLHS and CLtL2 - I feel I must have
> overlooked something.
Best I came up with was:
(multiple-value-bind (dollars cents) (truncate price)
(format t "$~:D~2,0$" dollars cents) )
_____________________________________________________________________________
Don Geddis ······@cadabra.com Phone 650-403-2220
Cadabra Inc. http://cadabra.com Fax 650-403-2201
1820 Gateway Drive, Suite 300, San Mateo, CA 94404 Main 650-403-2200
On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the
machine wrong figures, will the right answers come out?"