Hello Oleg;

Well, less generic because it assumes base 10. (Okay, I don't know how to produce based output, but I'm sure it may be in a future J.)

BTW, wouldn't

([: }. [: ": 10&[EMAIL PROTECTED] + ])"0

also work?  Or, is there an edge case, besides:

  5 ([EMAIL PROTECTED] {. [: ": 10&[EMAIL PROTECTED] + ]) _123
99877


Oleg Kobchenko wrote:
I think to use take with fill {.!.'0' is the
best generic method, but just for the record,
here's another yet more generic one:

   zeropad=: ([EMAIL PROTECTED] {. [: ": 10&[EMAIL PROTECTED] + ])"0
   5 zeropad 123 1234
00123
01234
   2 5 zeropad&.> 123 1234
+--+-----+
|23|01234|
+--+-----+


--- Randy MacDonald <[EMAIL PROTECTED]> wrote:

Hello Chris et al;

The documentation labels the r<..> tag as 'background text,' a term which doesn't strike me as mainstream. I would think of it more as 'blank prefix fill' or at least some phrase containing the word 'fill.' Its meaning is obvious once one knows the meaning.

That being said, I noticed one could get zero fill with use of Custom(!.) on Take ({.):

   _10{.!.'0']":12
0000000012


Chris Burke wrote:
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

--
------------------------------------------------------------------------
|\/| Randy A MacDonald       | APL: If you can say it, it's done.. (ram)
|/\| ramacd <at> nbnet.nb.ca |
|\ |                         | The only real problem with APL is that
BSc(Math) UNBF'83            | it is "still ahead of its time."
Sapere Aude                  |     - Morten Kromberg
Natural Born APL'er          |
-----------------------------------------------------(INTP)----{ gnat }-


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




      
____________________________________________________________________________________
Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


--
------------------------------------------------------------------------
|\/| Randy A MacDonald       | APL: If you can say it, it's done.. (ram)
|/\| ramacd <at> nbnet.nb.ca |
|\ |                         | The only real problem with APL is that
BSc(Math) UNBF'83            | it is "still ahead of its time."
Sapere Aude                  |     - Morten Kromberg
Natural Born APL'er          |
-----------------------------------------------------(INTP)----{ gnat }-


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to