For this C++ program...
#include <iostream>
using namespace std;
int main () {
float d = 0.1;
float e = 0.2;
float result = d + e;
bool is_equal = (result == 0.3);
cout << result << endl;
cout << is_equal << endl;
return 0;
}
The answer printed to the console is...
0.3
0
Questions:
- Why isn't the value of
result
equal to0.30000000000000004
, like it is in any other languages I've used (Ruby, JavaScript, Elixir)? - If the printed
result
is0.3
, why isn'tresult
equal to0.3
? - What is the actual value of
result
?