How to format an output using a racket

How to format the output with a racket? I want to print a fixed width number and fill it with 0 if it is small? hot to get it? I was looking for a rocket file, but I can find it fprintf, and it seems like I ca n't do it.

+4
source share
2 answers

You can use functions from the module racket/format. For example ~a:

#lang racket
(require racket/format)
(~a 42 
    #:align 'right
    #:width 4
    #:pad-string "0")

returns

"0042"
+7
source

formatin is #!racketnot as rich as sprintfin C. The workaround was to make eb yourself:

(require srfi/13)
(string-pad (number->string 23) 4 #\0) ; ==> "0023" 
+2
source

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


All Articles