本文介绍了服务器产生错误的数学的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个奇怪的...


我有一个简单的循环,可以增加价值。


似乎在成千上万之后使用这个循环没有

问题的实例,当循环尝试以下时,它会混乱。


strTotal = strTotal + strNewLabor


当strTotal = 3.2且strNewLabor = 1.7时,它会计算:

strTotal = 4.900001


为什么世界上会有类似的东西这发生了吗?


-

Sugapablo

---------------- --------------------
< - music
< - personal

Here''s a wierd one...

I have a simple loop that adds values.

It seems that after thousands of instances using this loop with no
problems whatsoever, when the loop tries the following, it messes up.

strTotal = strTotal + strNewLabor

When strTotal = 3.2 and strNewLabor = 1.7, it caluculates:
strTotal = 4.900001

Why in the world would somthing like this happen?

--
Sugapablo
------------------------------------
http://www.sugapablo.com <--music
http://www.sugapablo.net <--personal

推荐答案




3.2的二进制表示是什么? 1.7怎么样?每个都是

近似值,所以不要期望添加它们会提高它们的精度。请参阅以下内容:



这适用于使用浮点数的每种语言。

-

戴夫安德森


未经请求的商业电子邮件将以



What is the binary representation of 3.2? How about 1.7? Each is an
approximation, so there is no expectation that adding them will improve
their precision. See the following:

http://support.microsoft.com/default...;EN-US;q244699
This applies to every language that uses floating point numbers.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of








HTH,

Bob Barrows



http://support.microsoft.com/default...kb;EN-US;42980

HTH,
Bob Barrows


这篇关于服务器产生错误的数学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:07