你怎么得到一个printf %6.2f计划或球拍,就像你在C?
现在我只有printf "The area of the disk is ~s\n" ( - d1 d2),但我不能将输出格式化为特定的浮点格式.
谢谢
要获得更接近C printf()函数的行为,请使用SRFI-48format提供的过程,如下所示:
(require srfi/48)
(format "The area of the disk is ~6,2F~%" (- d1 d2))
Run Code Online (Sandbox Code Playgroud)
更详细的替代方案是使用Racket的内置~r程序,如@stchang所建议的那样:
(string-append
"The area of the disk is "
(~r (- d1 d2) #:min-width 6 #:precision '(= 2))
"\n")
Run Code Online (Sandbox Code Playgroud)