I\'m trying to find the n
th digit of an integer of an arbitrary length. I was going to convert the integer to a string and use the character at index n...
A direct answer is:
char Digit = 48 + ((int)(Number/pow(10,N)) % 10 );
You should include the <math>
library
const char digit = '0' + number.at(n);
Assuming number.at(n)
returns a decimal digit in the range 0...9, that is.
number = 123456789
n = 5
tmp1 = (int)(number / 10^n); // tmp1 = 12345
tmp2 = ((int)(tmp1/10))*10; // tmp2 = 12340
digit = tmp1 - tmp2; // digit = 5