I don't have my Arduino here so I can't test, but it works fine on Linux using int as long and short as int. Must be an Arduino integer or math library issue.
You will need to split the functionality up and see at what point it is failing:
int getDigit(long number, int place)
{
double p = pow(10, place - 1);
long l = long(p);
long n = number / l;
long m = n % 10;
// Debug output
Serial.print("getDigit() called, number = ");
Serial.print(number);
Serial.print(", place = ");
Serial.print(place);
Serial.print(", l = ");
Serial.print(l);
Serial.print(", n = ");
Serial.print(n);
Serial.print(", m = ");
Serial.println(m);
return int(m);
}
pow() returns a float. Arduino is MUCH happier with integers:
int getDigit(long number, int place)
{
for (; place>1; place--)
number /= 10; // Shift right one decimal digit
return number % 10; // Return rightmost decimal digit
}
... just noticed johnwasser already wrote code that works, so didn't need to include mine - however, it's already done, it's another variation, so I'll leave it be (sorry john - should have checked more carefully).