Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为什么是数学?对于同一个等式,圆形给出不同的值?_Asp.net_Vb.net_Math - Fatal编程技术网

Asp.net 为什么是数学?对于同一个等式,圆形给出不同的值?

Asp.net 为什么是数学?对于同一个等式,圆形给出不同的值?,asp.net,vb.net,math,Asp.net,Vb.net,Math,我正在使用Math.Round函数对十进制数进行三位精度的四舍五入,但对于某些等式,它给出了错误的结果。下面给出的代码给出了错误的结果。它给出了1.428,但预期结果是1.429 Math.Round(28.57 * 5.0 / 100, 3, MidpointRounding.AwayFromZero) Math.Round(28.57 * (5.0 / 100), 3, MidpointRounding.AwayFromZero) 我只是把5.0/100放在括号里就得到了正确的答案。下面

我正在使用Math.Round函数对十进制数进行三位精度的四舍五入,但对于某些等式,它给出了错误的结果。下面给出的代码给出了错误的结果。它给出了1.428,但预期结果是1.429

Math.Round(28.57 * 5.0 / 100, 3, MidpointRounding.AwayFromZero)
Math.Round(28.57 * (5.0 / 100), 3, MidpointRounding.AwayFromZero)
我只是把5.0/100放在括号里就得到了正确的答案。下面给出的代码给出了1.429

Math.Round(28.57 * 5.0 / 100, 3, MidpointRounding.AwayFromZero)
Math.Round(28.57 * (5.0 / 100), 3, MidpointRounding.AwayFromZero)

我不明白为什么会这样。你能解释一下吗?

通常,浮点数可能没有数字的“精确”表示形式,因此它们的精度不高

例如,如果您尝试减去两个表达式中的值,将得到非常小的结果