Dividing integers does not get a result

£可爱£侵袭症+ 提交于 2019-12-13 09:09:02

问题


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



来源:https://stackoverflow.com/questions/34724985/dividing-integers-does-not-get-a-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!