本文介绍了整数除法不会得到结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将2的整数相除并获得浮点数的结果,但是看来它不能正常工作.你能看到我在哪里做错了吗? sscanf部分正在工作,问题出在分割部分.
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推荐答案
您正在使用哪个编译器. gcc --version gcc(GCC)4.5.1 20100924(Red Hat 4.5.1-4)
Which compiler you are using . gcc --version gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
它给出以下结果.
val1 = 40 val2 = 55 val3 = 1792
val1 = 40 val2 = 55 val3 = 1792
结果= 40.919655
Result = 40.919655
更多推荐
整数除法不会得到结果
发布评论