For the number a , the assumption that it will have less than 28 decimal places is something compact and reliable:
numDP = length(num2str(a, 28)) - strfind(num2str(a, 28),'.');
Converting to string makes good use of string comparison functions in Matlab, although it's a bit awkward.
source share