【发布时间】:2014-02-10 09:27:37
【问题描述】:
在 Visual Studio 2010 中,我在 c# .net 中进行编程时发现表达式
var prs1 = (e.X * 100) / panel4.Width;
var prs2 = prs1;
var ans = (prs2 * panel2.Width) / 100;
pb2.Location = new Point(ans, 30);
还有另一个代码:
var prs1 = (e.X / panel4.Width) * 100;
var prs2 = prs1;
var ans = (prs2 /100) * panel2.Width;
pb2.Location = new Point(ans, 30);
//this code giving incorrect response
请告诉我两个代码在数学上是相等的,而不是为什么编译器没有给我相同的输出?
【问题讨论】:
-
你在用整数潜水,我很确定这就是问题的根源。你能把问题提取到一个特定的行吗?
标签: c# visual-studio-2010 c#-4.0 math logic