Sounds like you are in good shape, but here is a slightly different approach, just in case:
Break down this big formula into 5 formulas (digit1,digit2,digit3,etc.), each stripping out one of the 5 digits for comparison.
eg: iif(mid(totext(MyNumber),1,1)="","0",mid(totext(MyNumber),1,1))
That is, if the first digit is blank, return "0",
otherwise just return the Digit, in text format
Once you get all your formulas working, you can concatenate
them in one so that your output to ascii is nice and clean.
(eg: digit1+digit2+digit3...)
Good luck!