Printf% 6.2f in the circuit or racket?

How do you get printf %6.2f in a circuit or racket, like in C?

Now all I have is printf "The area of the disk is ~s\n" ( - d1 d2) , but I can’t format the output in a specific floating point format.

thanks

+6
source share
2 answers

To find the behavior closer to the C function printf() , use the format procedure provided by SRFI-48 , for example:

 (require srfi/48) (format "The area of the disk is ~6,2F~%" (- d1 d2)) 

A more complex alternative would be to use the ~r routine built into Racket, as suggested by @stchang:

 (string-append "The area of the disk is " (~r (- d1 d2) #:min-width 6 #:precision '(= 2)) "\n") 
+4
source

Racket has ~r .

You probably want to provide the arguments #:min-width and #:precision .

+4
source

Source: https://habr.com/ru/post/975904/


All Articles