Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

append string to float when format out

23 views
Skip to first unread message

Jinsong Zhao

unread,
Apr 18, 2014, 3:04:19 PM4/18/14
to
Hi there,

I am trying to output a large number of float numeric to a text file for
used by another program. It use D0 to indicate the type of double float.
I try it using format in Lisp. However, I have encountered some problem.
I prepared a mini example to demo what's the problem.

I have a list, for example:

'(1.2 1.555 1.3 22.12)

I hope to output it as:

1.200D0 1.555D0 1.300D0 22.120D0

The part of float is 8,4F, and then "D0" is append to the float. Is it
can be done using format? I know there is E directive, but it's not what
I want.

Now, what I have done is to output using 10,6F, and then substitute the
last 00 to D0 using a editor. It will be wonderful to do it by Lisp alone.

Thanks in advance.

Best regards,
Jinsong

Kaz Kylheku

unread,
Apr 18, 2014, 3:14:25 PM4/18/14
to
On 2014-04-18, Jinsong Zhao <jsz...@yeah.net> wrote:
> Hi there,
>
> I am trying to output a large number of float numeric to a text file for
> used by another program. It use D0 to indicate the type of double float.
> I try it using format in Lisp. However, I have encountered some problem.
> I prepared a mini example to demo what's the problem.
>
> I have a list, for example:
>
> '(1.2 1.555 1.3 22.12)
>
> I hope to output it as:
>
> 1.200D0 1.555D0 1.300D0 22.120D0
>
> The part of float is 8,4F, and then "D0" is append to the float. Is it
> can be done using format? I know there is E directive, but it's not what
> I want.

Am I missing something, as to why it can't just be this:

(format t "~,3fD0~%" 1.2)

?

Barry Margolin

unread,
Apr 18, 2014, 3:15:17 PM4/18/14
to
In article <lirsvl$f23$1...@dont-email.me>, Jinsong Zhao <jsz...@yeah.net>
wrote:
Am I missing something? Why can't you just put the D0 literally in the
format string?

(format "%8,4FD0" num)

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Pascal J. Bourguignon

unread,
Apr 18, 2014, 3:12:36 PM4/18/14
to
Jinsong Zhao <jsz...@yeah.net> writes:

> Hi there,
>
> I am trying to output a large number of float numeric to a text file
> for used by another program. It use D0 to indicate the type of double
> float. I try it using format in Lisp. However, I have encountered some
> problem. I prepared a mini example to demo what's the problem.
>
> I have a list, for example:
>
> '(1.2 1.555 1.3 22.12)
>
> I hope to output it as:
>
> 1.200D0 1.555D0 1.300D0 22.120D0
>
> The part of float is 8,4F, and then "D0" is append to the float. Is it
> can be done using format? I know there is E directive, but it's not
> what I want.

(format t "~{ ~8,4FDO~}~%" '(1.2 1.555 1.3 22.12))
prints:

1.2000DO 1.5550DO 1.3000DO 22.1200DO



--
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ? C'est le moment d'acheter !"

Jinsong Zhao

unread,
Apr 18, 2014, 3:51:59 PM4/18/14
to
Thanks a lot to all replies. I am so stupid not to try something like
it. It looks very simple.

Thanks again.

Best,
Jinsong

Kaz Kylheku

unread,
Apr 18, 2014, 3:54:27 PM4/18/14
to
On 2014-04-18, Jinsong Zhao <jsz...@yeah.net> wrote:
> Thanks a lot to all replies. I am so stupid not to try something like
> it. It looks very simple.

It also works with iteration over lists:

"~{~8,3fD0~}" (list 1.1 2.2 3.3)

everything between the ~{ and ~} is repeated, formating directives
as well as verbatim characters.
0 new messages