There are probably better solutions, but this one is slightly shorter:
int theNumber = 204398234;
int theDigitPlace = 3;//hundreds place
int theDigit = (theNumber/(int)(pow(10, theDigitPlace - 1))) % 10;
In your case, it divides the number by 100 to get 2043982 and then "extracts"
the last decimal digit with the "remainder operator" %
.
Remark: The solution assumes that the result of pow(10, theDigitPlace - 1)
is
exact. This works because double
has about 16 significant decimal digits and int
on iOS
is a 32-bit number and has at most 10 decimal digits.