Dividing integers does not get a result

2019-10-03 03:50发布

问题:

I'm trying to divide 2 integer and get the float results but it does not seem it is working properly. Can you see where am i doing wrong? sscanf part is working, the problem is at the dividing part.

char *latitude = "4055,1792.N";
int val1;
int val2;
int val3;
float result;

sscanf ( latitude, "%2d%2d,%4d", &val1, &val2, &val3);
printf("\r\nval1 = %d val2 = %d val3 = %d\r\n",val1,val2,val3);
result = val1 + (float)val2/(float)60 + (float)val3/(float)600000;

printf("\r\nResult = %f\r\n",result);
printf("\r\nEnd\r\n");

This code does not result this operation. Here is the output:

val1 = 40 val2 = 55 val3 = 1792                                                 

Result =                                                                        

End

回答1:

Which compiler you are using . gcc --version gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)

It gives following result .

val1 = 40 val2 = 55 val3 = 1792

Result = 40.919655