Excellent function, works really well. I made a few changes that extends this program for semilogx, semilogy, and loglog plots. Check it out here: http://www.mathworks.com/matlabcentral/fileexchange/46431-format-tick-labels--extended-v2-
This function should not be used except with the understanding that it is subject to errors at certain values (e.g., as @Will pointed out) due to the nature of floating-point. It's also not even vectorized!