[racket] Formatted output of floating-point numbers?

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Thu Jan 12 14:01:13 EST 2012

On 01/12/2012 03:53 AM, Dmitry Pavlov wrote:
> Hello all,
>
> I have been looking for a way to do in Racket
> something you can easily do in C:
>
> printf("%10.5lf\n", 12.345678);
>
> so it properly cuts the fractional part to 5 digits
> and adds padding to get 10 characters in total,
> producing "  12.34568" as a result.

This is supported by SRFI 48: Intermediate Format Strings, which is 
already provided with Racket.

 > (require (prefix-in srfi: srfi/48)) ;; avoid shadowing racket's format
 > (srfi:format "~10,5F" 12.345678901)
"  12.34568"

Ryan


Posted on the users mailing list.