0
why 0? c++
#include <iostream> using namespace std; int main() { double a = 0.1, b=0.2,c=0.3; cout<<((a+b)==c); return 0; }
4 ответов
+ 4
You compare doubles for equality.
See floating point precision:
https://learn.microsoft.com/en-us/cpp/build/why-floating-point-numbers-may-lose-precision?view=msvc-170
+ 3
This is described in the link that I provided.
0
so how to compare floats?
0
You can compare floats only up to a predefined precision. That precision is up to you and the requirements of your program.