VB2010中奇怪的数学错误 [英] weird math error in VB2010
本文介绍了VB2010中奇怪的数学错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码:
x1 = 2305/4096
x5 = 4096
r = 2025
x1 = r / x5
导致两个实例都是x1最终为1,而不是0。
r,x1和x5定义为int32。
解决任何人?
使用VB作为补充的嵌入式应用程序开发人员
解决方案
它正在舍入向上群组。 2025/4096大于.5因此它变为1.
你会想要使用Math.Floor(r / x5)
the following code:
x1 = 2305 / 4096
x5 = 4096
r = 2025
x1 = r / x5
results in both instances is that x1 ends up being 1, and not 0 as it should.
r, x1 and x5 are defined as int32.
solution anyone?
developer of embedded apps using VB as complement
解决方案
It is rounding up. 2025/4096 is greater than .5 so it becomes 1.
You will want to use Math.Floor(r/x5)
这篇关于VB2010中奇怪的数学错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文