This submission just seems to replicate the behavior of MATLABs inbuilt functions "sprintf"/"fprintf":
A drop-in replacement for this submission can thus be easily defined in one line:
fun = @(num,dgt) sprintf('%0*i',dgt,num);
The submission is also much slower and offers much less control over the output format than "sprintf", although that error checking may be useful to someone.
Great function. I should find it earlier.
Will, it's a precision problem of floating point arithmetic. Try:
This little number trigger the balance. I think it's hard to overcome.