> 5.0>true
> 5.2>false< /p>
In order to do this, I do an if (result mod 1) = 0 and see if it returns true or false. Consider the result is twofold. By the way, the compiler gives me this error:
[dcc32 Error] Unit1.pas(121): E2015 Operator not applicable to this
operand type
How can I solve this problem? Please note that my number format is ##.##### so I don’t have much problem with floating point precision.
Generally speaking, I will use if (result %1 == 0) {}But this does not work in Delphi.
if (frac(result) = 0) then
ShowMessage('is zero')
else
ShowMessage('is NOT zero');
end;
For more information about this feature, please check the documentation. What you are doing is wrong, because in In Delphi, the keyword mod only applies to integers.
Note. I tested this with numbers such as 45.1234, and the code is correct. I see that there are some numbers in your double numbers, so don’t There should be a problem. I’m not sure how accurate the function is, but in this case you don’t have to worry about it.
I need to test whether a double is an integer. Basically this is An example of the rule:
> 5.0>True
> 5.2>False
In order to do this, I do an if(result mod 1)=0 Then see if it returns true or false. Consider the result is twofold. By the way, the compiler gave me this error:
[dcc32 Error] Unit1. pas(121): E2015 Operator not applicable to this
operand type
How can I solve this problem? Please note that my number format is ##.##### so I don’t have much problem with floating point precision.
Generally speaking, I will use if (result %1 == 0) {}But this does not work in Delphi.
You can use the function frac declared in the System unit of Delphi. Try this code:
if (frac(result) = 0) then
ShowMessage('is zero')
else
ShowMessage('is NOT zero');
end;
For more information about the function, please check the documentation. What you are doing is wrong, because in Delphi, the keyword mod only applies to integers.
end;
/p>
Note. I tested this with numbers such as 45.1234 and the code is correct. I see that there are some numbers in your double numbers, so there should not be a problem. I am not sure how accurate the function is , But in this case you don’t have to worry.