We are facing issue with data type double comparison:
if(p > pmax) then
begin
Showmessage('');
end
If both values are 100 (p=100 and pmax = 100), then also it is going inside if clause.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are several problems with comparing Doubles. One problem is that what you see is not exactly what you get due to rounding. You can have 99.999999996423 and 100.00000000001632, which are both rounded to 100, but they are not equal.
The solution is to use a margin so that, if the difference of the two Doubles lies within the margin, you accept them as equal.
You can create an IsEqual function using the margin as an optional parameter: