ten digits in pi in matlab

To get ten digits of pi in Matlab, you can use the following code:

main.m
format long           % set format to display many decimal places
pi_digits = num2str(pi, 11);   % convert pi to a string with 11 characters
disp(['Pi to ten digits: ' pi_digits])
180 chars
4 lines

The format long command sets the display format to show many decimal places. The num2str function converts the value of pi to a string with 11 characters (the first two characters are "3." and the remaining nine characters are the ten digits of pi).

The result should be displayed as:

main.m
Pi to ten digits: 3.1415926536
31 chars
2 lines

related categories

gistlibby LogSnag