MATLAB: Changing number of digits digitspi I am trying to display the exact first 6 digits of pi how to do that ? Best Answer Here is one way to display the first 6 digits of pi (after the decimal place) ...sprintf('%6f',pi)See the details, e.g. format specification, in the documentation for sprintf. Related SolutionsMATLAB: Matching digits A=1234; B=1248; C =1238;Astr = num2str(A); %you'll need this one 3x so convert it once.idxstop = find(any(bsxfun(@ne,vertcat(Astr,num2str(B),num2str(C)),Astr),1),1,'first');common = Astr(1:idxstop-1) MATLAB: Left digits left3 = @(x)str2double(x(1:3));left3(num2str(1234))Perhaps?Or so it doesn't error on numbers < 100left3 = @(x)str2double(x(1:min(3,length(x)))); Related QuestionThree-digit format
Best Answer