MATLAB: How to get the value a number at a specify decimal position

decimalhomeworkvector

hi, If I have
pi=3.1415926535897932384626433832795028
I want to get the value of lets say 10th number after the comma.
n = 5;
it this possible? I though I could convert the number to a vector
and then proced with index but i dont know how to get a vector out the given decimal number. thanks

Best Answer

Use sprintf, find the decimal point, then get the desired digit after the decimal point. That being said, realize that for some numbers there may be rounding involved in the string output so if you push this technique to the limit it can become a much more difficult problem.