We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
17.45*0.9*3 = 47.115
17.45*3*0.9 = 47.114999999999995
打个比方,我们知道尺这个单位,一米等于三尺,如果我要买一尺红布,两尺黑布,那我需要把一米红布的三分之一拿出来,但是一米布的三分之一并不确定,因为他是一个无限循环的小数,所以只能取一个大概的值 两尺黑布同理也是一个不确定的值,这样当红布和黑布加在一起,并不一定就长一米,而是接近一米。
上面的例子就和我们0.1+0.2 != 0.3 一个道理,因为需要将0.1转化为二进制,将0.2转化为二进制,然后将两个二进制相加后再转为10进制,就在转化的过程中出现了偏差(类比尺和米的转化),所以导致结果并不是我们期望的那样,而是一个近似值。
解决方法:
(0.1*10 + 0.2*10) / 10 = 0.3
The text was updated successfully, but these errors were encountered:
No branches or pull requests
17.45*0.9*3 = 47.115
,调换顺序后17.45*3*0.9 = 47.114999999999995
就算保留两位小数,那也不相等。所以需要保证两个地方的计算顺序一致上面的例子就和我们0.1+0.2 != 0.3 一个道理,因为需要将0.1转化为二进制,将0.2转化为二进制,然后将两个二进制相加后再转为10进制,就在转化的过程中出现了偏差(类比尺和米的转化),所以导致结果并不是我们期望的那样,而是一个近似值。
解决方法:
(0.1*10 + 0.2*10) / 10 = 0.3
就是成立的了The text was updated successfully, but these errors were encountered: