在VB6中非常奇怪 [英] Very strange thing in VB6

查看:76
本文介绍了在VB6中非常奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我在VB6中看到了一些非常奇怪的东西


如果我做一个Int((5 * 1.2)),我收到的价值是5,但是我应该收到6?

这是一个错误还是真正正常的东西。

如果我这样做我可以看到

? int((5 * 1.2 + 0.0000000000000003))

我收到6.如果我添加更小的东西,我就有5个结果

有什么奇怪的,如果我做的话一个 ? 5 * 1.2,我收到6所以(5 * 1.2)

应该做6

如果我做Int((5 * 12/10)),结果还行(6)

我能做些什么才能让它正确?

VB6中有一个选项吗?


谢谢

Marc Allard

Allcomp

Hello,

I have seen something really strange in VB6

If I do a Int ( (5 * 1.2)) , I receive the value 5, but I should receive 6?
Is this a bug or something really "normal".
I can see that if I do
? int ((5 * 1.2 + 0.0000000000000003))
I receive 6. If I add something smaller, I have 5 as a result
What is strange is that If I do a ? 5*1.2, I receive 6 so (5 * 1.2)
should do 6
If I do Int ( (5 * 12 / 10)), the result is OK (6)
What can I do to have it correct?
Is there an option in VB6?

Thank you
Marc Allard
Allcomp

推荐答案

2005年4月27日星期三10:35:31 +0200 Allcomp< ma ** @ nospam.allcomp.be>写道:
On Wed, 27 Apr 2005 10:35:31 +0200 Allcomp <ma**@nospam.allcomp.be> wrote:
*来自:* Allcomp< ma ** @nospam.allcomp.be>
*日期:*星期三,2005年4月27日10:35:31 + 0200

您好,

我在VB6中看到了一些非常奇怪的东西

如果我做一个Int((5 * 1.2)),我会收到值5,但我应该收到6?
这是一个错误还是真正正常的东西。
我可以看到,如果我这样做了吗? int((5 * 1.2 + 0.0000000000000003))
我收到6.如果我添加更小的东西,我有5个结果
有什么奇怪的,如果我做了? 5 * 1.2,我收6个所以(5 * 1.2)
应该做6
如果我做Int((5 * 12/10)),结果还可以(6)
什么我可以做到正确吗?
VB6中有没有选项?

谢谢
Marc Allard
Allcomp
*From:* Allcomp <ma**@nospam.allcomp.be>
*Date:* Wed, 27 Apr 2005 10:35:31 +0200

Hello,

I have seen something really strange in VB6

If I do a Int ( (5 * 1.2)) , I receive the value 5, but I should receive 6?
Is this a bug or something really "normal".
I can see that if I do
? int ((5 * 1.2 + 0.0000000000000003))
I receive 6. If I add something smaller, I have 5 as a result
What is strange is that If I do a ? 5*1.2, I receive 6 so (5 * 1.2)
should do 6
If I do Int ( (5 * 12 / 10)), the result is OK (6)
What can I do to have it correct?
Is there an option in VB6?

Thank you
Marc Allard
Allcomp




这不是典型的使用二进制时经常产生的不准确吗?

操纵十进制数字?


我怀疑实际结果可能类似于5.999999999(等)和

INT将是5.使用Cint(5 * 1.2)将给出6的正确答案

Cint圆形分数,而INT则没有。


克里斯。



Isn''t this just typical of the inaccuracies often produced when using binary to
manipulate decimal numbers?

I suspect the actual result is probably something like 5.999999999 (etc) and the
INT of that will be 5. Using Cint(5 * 1.2) will give the correct answer of 6 as
Cint round fractions whereas INT does not.

Chris.


> >我在VB6中看到了一些非常奇怪的东西
> > I have seen something really strange in VB6

如果我做Int((5 * 1.2)),我会收到值5,但我应该
收到6?这是一个错误还是真正正常的东西。
我可以看到,如果我这样做了吗? int((5 * 1.2 + 0.0000000000000003))
我收到6.如果我添加更小的东西,我有5个结果
有什么奇怪的,如果我做了? 5 * 1.2,我收6个所以(5 * 1.2)
应该做6
如果我做Int((5 * 12/10)),结果还可以(6)
什么我可以做到正确吗?
VB6中有没有选项?

谢谢
Marc Allard
Allcomp

Isn'当使用二进制来操作十进制数时,这只是典型的不准确吗?

If I do a Int ( (5 * 1.2)) , I receive the value 5, but I should receive 6? Is this a bug or something really "normal".
I can see that if I do
? int ((5 * 1.2 + 0.0000000000000003))
I receive 6. If I add something smaller, I have 5 as a result
What is strange is that If I do a ? 5*1.2, I receive 6 so (5 * 1.2)
should do 6
If I do Int ( (5 * 12 / 10)), the result is OK (6)
What can I do to have it correct?
Is there an option in VB6?

Thank you
Marc Allard
Allcomp

Isn''t this just typical of the inaccuracies often produced
when using binary to manipulate decimal numbers?




是的。请参阅 http://support.microsoft.com /default...kb;en-us;42980

了解更多详情。


我怀疑实际结果可能是某事/>如5.999999999(等),其中的INT将为5.


如果执行此声明:打印5 * 1.2 - 6

您将得到-2.22044604925031E-16作为回复,证明5 * 1.2是

当上述文章的考虑因素保留在

时,不完全是6。


使用Cint(5 * 1.2)将给出正确答案6作为Cint圆形分数,而INT则没有。



Yes. See http://support.microsoft.com/default...kb;en-us;42980
for more details.

I suspect the actual result is probably something
like 5.999999999 (etc) and the INT of that will be 5.
If you execute this statement: Print 5 * 1.2 - 6
You will get -2.22044604925031E-16 as a response proving that 5*1.2 is
not exactly 6 when the considerations of the above article are kept in
mind.

Using Cint(5 * 1.2) will give the correct answer of 6 as
Cint round fractions whereas INT does not.




该建议的唯一问题是CInt功能使用了Banker'的
Rounding,因此您可能仍然会得到意想不到的结果(因为不同的原因比上面的b
)。 ..


MsgBox CInt(3 * 1.5)

显示4,不是预期的价值5.

Rick - MVP



The only problem with that suggestion is the CInt function uses Banker''s
Rounding, so you may still get unexpected results (for a different
reason than above)...

MsgBox CInt(3 * 1.5)

displays 4, not the expected value of 5.
Rick - MVP


>我在VB6中看到了一些非常奇怪的东西
> I have seen something really strange in VB6

如果我做一个Int((5 * 1.2)),我会收到值5,但我应该
收到6?这是一个错误还是真正正常的东西。
我可以看到,如果我这样做了吗? int((5 * 1.2 + 0.0000000000000003))
我收到6.如果我添加更小的东西,我有5个结果
有什么奇怪的,如果我做了? 5 * 1.2,我收6个所以(5 * 1.2)
应该做6
如果我做Int((5 * 12/10)),结果还可以(6)
什么我可以做到正确吗?
VB6中有选项吗?

If I do a Int ( (5 * 1.2)) , I receive the value 5, but I should receive 6? Is this a bug or something really "normal".
I can see that if I do
? int ((5 * 1.2 + 0.0000000000000003))
I receive 6. If I add something smaller, I have 5 as a result
What is strange is that If I do a ? 5*1.2, I receive 6 so (5 * 1.2)
should do 6
If I do Int ( (5 * 12 / 10)), the result is OK (6)
What can I do to have it correct?
Is there an option in VB6?




请参阅我对Chris发布的回复,了解您的原因

看你写的内容。解决方案是使用格式函数

,因为这样可以避免尝试将一个非精确二进制值填入二进制表示形式时产生的舍入错误。并且,格式

函数也使用正常舍入而不是Banker'的舍入。所以,

用这个代替你的陈述,它会正常工作。


打印格式(5 * 1.2,0)


Rick - MVP



See my response to Chris'' posting for some explanation of why you are
seeing what you wrote about. The solution is to use the Format function
as this avoids the round-off errors that come from trying to cram a
non-exact binary value into a binary representation. And, the Format
function also uses normal rounding instead of Banker''s Rounding. So,
replace your statement with this and it will work fine.

Print Format(5 * 1.2, "0")

Rick - MVP


这篇关于在VB6中非常奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆