0.1 + 0.7 != 0.8 [duplicate]
-
14-10-2019 - |
Question
Possible Duplicate:
Is JavaScript's Math broken?
Why in some programming languages the expression in title evaluates to true? I've tried it in php, ruby and python.
Solution
OTHER TIPS
double TOLERANCE < 1.0E-10;
if(fabs(0.1+0.7-0.8)< TOLERANCE)
{
std::cout << "0.1 + 0.7 == 0.8" << std::endl;
}
else
{
std::cout << "0.1 + 0.7 != 0.8" << std::endl;
}
Because of internal interpretation of floating-point numbers, they do not exactly equal to what you have wrote.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow