Formatting of complex numbers

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...
Post Reply
Leo
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm

Formatting of complex numbers

Post by Leo »

Hello DyalogAPL'er,
How to write Format Commands for Complex Numbers for an Output Log?

Example:
Instead of
2.500000000E000J4.330127019
should in the result list appear
2.5000J4.330
or
2.50E0J4.33E1

Many thanks in advance for your help!

Leo
Roger|Dyalog
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Formatting of complex numbers

Post by Roger|Dyalog »

One way: format the real and imaginary parts separately, then combine. For example:

      y←2.5j4.330127019

¯3{1↓∊⍺{'J',1↓⍺⍕⍵}¨9 11○⍵}y
2.50E0J4.33E0
3{1↓∊⍺{'J',1↓⍺⍕⍵}¨9 11○⍵}y
2.500J4.330
Leo
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm

Re: Formatting of complex numbers

Post by Leo »

Hello Roger,
thank you for the quick help!
Leo
Post Reply