Extracting digits after decimal MATLAB -


i representing chaotic number 15 digits after decimal i.e format long in matlab , want extract 3 numbers each containing 5 digits chaotic number. i.e if chaotic no. 0.d1d2...d15 want (d1..d5),(d6..d10) & (d11..d15). rounding off.i have written following code.

num=x(n); a1=floor(num*10^5); disp('a1'); disp(a1); a2=floor(num*10^10-a1*10^5); disp(a2); num=floor(num*10^15); a3=mod(num,100000); disp('a3'); disp(a3); 

and output is

0.320446597556797  a1    32044 a2    65975  a3    56796 

its showing a3 56796 want 56797.

please help!!!

the problem is, likely, each operation extract group of digits introduces small error, reflected in last digit.

an alternative approach avoids this:

num = pi; %// example str = num2str(num,'%0.15f'); %// string representation 15 decimal digits str = str(find(str=='.')+1:end); %// keep digits after decimal point = base2dec(reshape(str,5,[]).',10); %'// convert string parts numbers 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -