Visual Studio中的简单减法,结果不正确

时间:2015-03-25 03:18:57

标签: vb.net visual-studio-2012

做一个简单的减法,例如:

   Dim a, b As Double
   a = 81.4
   b = 76.0
   MsgBox(a - b)

你会期望它会产生5.4但是你获得5.4000000000000001 发生了什么事?

1 个答案:

答案 0 :(得分:2)

浮点数,即使是双精度浮点数,也不是具有无限精度的“实数”。

请参阅What Every Computer Scientist Should Know About Floating-Point Arithmetic

Bruce Dawson's blog

Wikipedia