I may be trying to accomplish the impossible but being aware of FormatFloat & FloatToStrF I can't find a means by which the opposite may be accomplished.
Given a String '2.5625' I want to return the number 2.5625 NOT 2.562500023841 . . . . . .
I am aware of 'SameValue' using a small value for the tolerance but have not been able to use that effectively.
This question arose due to an incorrect comparison failure which I still cannot fathom. I created a new Project to demonstrate the issue but was surprised when I couldn't reproduce the same result that I had seen in my main project. This involves comparing two values to determine if the first is an integer.
Good := (T1*Ratio) = Int(T1*Ratio);
In the main project, with T1 (byte) being 20 and Ratio (Single) being 2.54999952
(which ought to be 2.55) 'Good' is [False]
but I KNOW that 20x2.55 = 51 (integer)
whereas in the test project:
Good := (G1*Ratio) = Int(G1*Ratio);
with G1 (byte) = 20 and Ratio exactly as before, Good returns [True] !
A .zip file of the test project is attached.
I've found a way to force the correct result (for 'Good') in the main project by adding two variables declared as 'single' and comparing those :
A := T1*Ratio;
B := Int(A);
Good := A = B;
... but the logic behind this defeats me.