display 13 digits of pi in matlab

To display 13 digits of pi in MATLAB, you need to use the format long command, which sets the output format to floating-point numbers with 15 digits of precision. However, since pi itself is only known to 13 digits, setting the format to "long" will display pi to its maximum precision:

main.m
format long
pi
15 chars
3 lines

This will display the value of pi with up to 15 digits of precision, which is 3.141592653589793. Note that the last two digits are already rounded off. If you want to display pi with exactly 13 digits of precision, you can use fprintf command with format specifier %.13f:

main.m
fprintf('%.13f\n', pi)
23 chars
2 lines

This will display pi with exactly 13 digits of precision: 3.1415926535898. Note that the last digit is rounded off.

related categories

gistlibby LogSnag