I have this utility I've used for a while: lead0s=: [: ]`>@.(1 = [: # ,) ('r<0>' , '.0' ,~ [: ": [) 8!:0 [: | [: ".`]@.(0 = [: {. 0 # ]) ] 3 lead0s i. 3 +---+---+---+ |000|001|002| +---+---+---+ 3 lead0s 10^i. 4 +---+---+---+---+ |001|010|100|***| +---+---+---+---+ Since it uses format, it returns asterisks for arguments that are too large. It also does not handle negative numbers or non-integers.
On Sun, Feb 3, 2019 at 11:25 AM Raul Miller <rauldmil...@gmail.com> wrote: > I think this was the only suggestion which didn’t require specifying the > number of digits in some way... > > — > Raul > > On Sunday, February 3, 2019, R.E. Boss <r.e.b...@outlook.com> wrote: > > > ,' '([,.~ -.~"1) ":10#.^:_1 a > > 0001 0002 0003 0004 0005 0010 0020 0030 0040 0050 0100 0200 0300 0400 > 0500 > > 1000 2000 3000 4000 5000 > > > > > > R.E. Boss > > > > > > > -----Oorspronkelijk bericht----- > > > Van: Programming <programming-boun...@forums.jsoftware.com> > > > Namens 'Mike Day' via Programming > > > Verzonden: zondag 3 februari 2019 10:55 > > > Aan: programm...@jsoftware.com > > > Onderwerp: Re: [Jprogramming] Adding leading zeros > > > > > > Paolo has just beaten me to it, but I'll post this anyway. > > > > > > b NB. shorter than a, just to avoid line-wrapping > > > 1 10 100 1000 2 20 200 2000 3 30 300 3000 > > > > > > Monadic, with 4 and '000' embedded: > > > > > > (,@:((' ',~_4{.'000',":)"0)) b > > > 0001 0010 0100 1000 0002 0020 0200 2000 0003 0030 0300 3000 > > > > > > Dyadic - Essentially the same idea, but with 4 as a left argument: > > > > > > 4 (,@:((-@[ (' ',~ {.) ('0'#~[), ":@])"0)) b > > > 0001 0010 0100 1000 0002 0020 0200 2000 0003 0030 0300 3000 > > > > > > Note: > > > 0) for a sufficiently long numeric vector, you WILL need to deal with > > line- > > > wrapping! > > > 1) I couldn't see that the format foreigns, 8!:0 - 8!:2, cater for > > optional leading > > > zeros > > > 2) NuVoc mentions the printf addon, which emulates C's printf. It was > > > contributed by Henry Rich, so he should be able to explain it when he > > gets on > > > line. > > > Cheers, > > > Mike > > > > > > On 03/02/2019 08:36, 'Skip Cave' via Programming wrote: > > > > What's the best way to add leading zeros to a set of integers. How to > > > > design a verb f, that does the following: > > > > > > > > a =. 1 2 3 4 5 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 > > > > 4000 > > > > 5000 > > > > 4 f a NB. make each integer a total of 4 digits using leading zeros. > > > > 0001 0002 0003 0004 0005 0010 0020 0030 0040 0050 0100 0200 0300 0400 > > > > 0500 > > > > 1000 2000 3000 4000 5000 > > > > > > > > Skip > > > > > ---------------------------------------------------------------------- > > > > For information about J forums see > > > http://www.jsoftware.com/forums.htm > > > > > > --- > > > This email has been checked for viruses by Avast antivirus software. > > > https://www.avast.com/antivirus > > > > > > ---------------------------------------------------------------------- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm -- Devon McCormick, CFA Quantitative Consultant ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm