Finding a Specific Digit of a Number

Maxpm picture Maxpm · Dec 10, 2010 · Viewed 14.8k times · Source

I'm trying to find the nth 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...

char Digit = itoa(Number).at(n);

...But then I realized the itoa function isn't standard. Is there any other way to do this?

Answer

Cheers and hth. - Alf picture Cheers and hth. - Alf · Dec 10, 2010

(number/intPower(10, n))%10

just define the function intPower.