1. ## A casting problem?

Hello there,

I am having some strange results when trying to compute a simple math calculation. Can anyone please have a look at this code?

Code:
```	for (i=N_DISPLAY-1 ; i>=0 ; i--)
{
digitos[i] = v_digito/(int)pow(10, (double)i);

v_digito = v_digito - digitos[i]*(int)pow(10, (double)i);
}```
digitos[], i and v_digito are int types. pow is:

double pow (double a, double b);

What I am trying to do is to extract each of the algarisms of a number.

Debuging I found out the firs expression seens to be Ok, but the second simple ads 1 or 2 to the desired number to be stored at v_digito.

I suspect it is a casting problem as when I "play" with then I get diferent results, but none good..

Can anyone help? Thank you!

2. Code:
```        int N_DISPLAY = 4;
int digitos[4];
int v_digito = 7653;
int i;

for (i=N_DISPLAY-1 ; i>=0 ; i--)
{
digitos[i] = v_digito/(int)pow(10.0, (double)i);
printf("%ld\n", digitos[i]);

v_digito = v_digito - digitos[i]*(int)pow(10, (double)i);
printf("%ld\n",v_digito);
}```
This is what I run and the answer seems to be fine...
Could you explain further what is the problem?

Code:
```My answer:
7
653
6
53
5
3
3
0```
also tried the following variations and everything seems ok.
Code:
```digitos[i] = (int) ((double)v_digito/pow(10.0, (double)i));
v_digito = v_digito - digitos[i]*pow(10, (double)i);```
;

In the second expression, there is no necessity of casting.

Regards

3. Originally Posted by nacho4d
In the second expression, there is no necessity of casting.

Regards
Hello there, I removed this casting and it is working now!

Thank you!