11-27-06 06:29 AM
Hello Robert,
> I'm trying to define a bc function that will pad an integer with
> leading 0s.
>
> For example, I want pad(57,4) -> 0057; pad(593,2) -> 593
>
> This definition of pad puts the correct number of leading 0s, but it
> also adds a trailing 0. I don't know why.
>
> ####
> define pad(x,y){
> auto w
> w=y-length(x)
> while(w>0){print"0";w-=1}
> print x
> }
> ####
The trailing '0' you are seeing is in fact the return value of the
pad() function. Doing something like:
ret = pad(57,4)
should produce the 'correct' output.
HTH,
Loic.
[ Post a follow-up to this message ]
|