On Jan 20, 10:23 am, jimka <·····@rdrop.com> wrote:
> (format nil "~4,3F" some-number)
> will print eactly 3 digits after the decimal, if some-number is 3.2,
> then it prints 3.200. How can i tell format to
> supress the trailing 0's? anybody know?
> obviously i could as format to print to a string, then post-process
> the string... but maybe there's an easier way.
>
> -jim
Format ~4,3F is a little weird, by the way,.. you are not going to get
a leading zero either for 0.211 unless you give it ~5,3 since the
decimal point is counted against the first parameter.
Assuming the leading zero is ok... simply just ~4F (or ~5F) seems to
do (mostly) what you want except when it's just 3.2 or something like
3.201 you will get " 3.2", (note the leading space) since you forced
it to be 4 characters wide. if you can tolerate that? that's
probably your best bet.
As an alternative to Alexander's function of consing up the format
string you could put your number through a function that just lops off
precision below the level you wanted before passing it to simply
format ~F.
Kevin