Wow. Thanks Chris.
Now I get it ... when I was trying out the new format function I wasn't passing
it the complete parameters like so:
NB. convert to zero padded 2 digits
'r<00>' 8!:0 2
|rank error
| 'r<00>' 8!:0 2
So now I can just write my zero pad function as:
zeropad=: dyad define
('r<0>' append (format x) append '.0') (8!:2) y
)
5 zeropad 3
00003
5 zeropad each increment integers 10
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│00001│00002│00003│00004│00005│00006│00007│00008│00009│00010│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
This is great! Thanks again. :)
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Burke
Sent: Tuesday, December 04, 2007 3:38 PM
To: General forum
Subject: Re: [Jgeneral] Need help with 8!:0
Alex Rufon wrote:
> I've been using the standard ": function for a while and I wanted to use
> the new one ... 8!:0. Unfortunately, the documentation kept throwing me
>
> For a real world example, since my work normally interfaces with SAP and
> AS400 systems ... I normally have to format numbers with ZERO padding.
>
> So I made this generic zero padder to handle the formatting:
>
> zeropad=: dyad define
>
> data=. format y
>
> count=. x
>
> if. count largerthan tally data do.
>
> data=. ((count minus tally data) copy '0') append data
>
> end.
>
> data
>
> )
>
>
>
> If you run this (please load the 'primitives' library first)
>
> 5 zeropad 20
>
> 00020
>
> So how do I do the same thing using 8!:0? I did give it a whirl and it
> seems that 8!:0 only works with arrays. Hmmm. Am I missing something?
'r<0>5.0' (8!:2) 123
00123
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm