Formatting of complex numbers

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Formatting of complex numbers

Postby Leo on Mon Dec 18, 2017 4:50 pm

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
Leo
 
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm

Re: Formatting of complex numbers

Postby Roger|Dyalog on Mon Dec 18, 2017 6:32 pm

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
Roger|Dyalog
 
Posts: 238
Joined: Thu Jul 28, 2011 10:53 am

Re: Formatting of complex numbers

Postby Leo on Tue Dec 19, 2017 10:34 am

Hello Roger,
thank you for the quick help!
Leo
Leo
 
Posts: 38
Joined: Mon Sep 18, 2017 12:10 pm


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest