I have two double variable. double a = 0.10000, double b = 0.1. How can I make sure the comparison (a == b) is always true ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If you are being paranoid about using ==
on doubles
or floats
(which you should be) you can always check that they are close within a small tolerance.
bool same = fabs(a-b) < 0.000001;