[racket-dev] Preserving trailing zeros in formatting numbers as strings

From: Kathi Fisler (kfisler at cs.wpi.edu)
Date: Fri May 2 17:04:10 EDT 2014

Thanks, Asumu.  I hadn't known about the ~r-like formatters.

Kathi


On Fri, May 2, 2014 at 4:52 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:

> On 2014-04-24 05:25:07 -0400, Kathi Fisler wrote:
> >    I'm generating class notes in HTML via scribble.  I'm trying to
> include
> >    the number 10.50 (as a price in an test case, so the trailing 0
> matters).
> >     I'm using format to produce the strings that go into the rendered
> html.
> >     When I do this (whether with ~a or ~s), the trailing 0 is dropped,
> >    producing 10.5 in my output instead of 10.50.
>
> Maybe this is too late to be useful (I think the mailing list ate your
> post?), but here's one way to do it:
>
>   > (~r 10.5 #:precision '(= 2))
>   "10.50"
>
> Cheers,
> Asumu
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20140502/3e61aeb3/attachment-0001.html>

Posted on the dev mailing list.