Hi,
I've got this:
"helpers.rkt"> (format "~0,0F" 1.22)
"1."
"helpers.rkt"> (format "~0,0F" 1.55)
"2."
I'd be satisfied with the same without the decimal point. Is there a way?
Hi,
I've got this:
"helpers.rkt"> (format "~0,0F" 1.22)
"1."
"helpers.rkt"> (format "~0,0F" 1.55)
"2."
I'd be satisfied with the same without the decimal point. Is there a way?
The decimal point is always added when ~F renders a number, even if it's an exact integer; this seems to be the traditional behavior; Common Lisp's format does it, as do functions like SRFI-48's that are influenced by it.
You can use ~r from the racket/format module instead:
> (~r 1.23 #:precision 0)
"1"
> (~r 1.55 #:precision 0)
"2"
Thanks! Do I have to use it with format like this?
(format "~a~a" (~r qt #:precision 0) unit)
~r returns a string, so you can use display, write-string, printf, SRFI-48 format, etc. to print it. Lots of options.
Aside/blatent self-promotion: I suggest my Racket port of the Scheme version of Common Lisp format from SLIB instead of SRFI-48 for anything complicated as it supports far more functionality.
You can also use the ~a function:
(~a (~r qt #:precision 0) unit)