What are the different posibilities of getting "Invalid floating point operation" in dephi applications?

Recommended Answers

All 2 Replies

Many, basically trying to do something not matematically possible: Divide by cero, log of a negative number, sqrt of a negative number... and also operations with a result out of the limits: a:= Power(999,999) for instance won't fit in your PC!

Hi There,

This issue usually occurs when you attempt to convert a null string to a floating point, for instance:

[var
\ MyFloat : Double; {or extended if you want}

procedure Button1OnClick(Sender : TObject);
begin
MyFloat := StrToFloat(Edit1.Text); {<== Error occurs here when Edit1.Text is empty}
end;

]

To fix this problem is easy. Simply use the alternative type casting function StrToFloatDef(String Value, Default Float). So:

[var
\ MyFloat : Double; {or extended if you want}

procedure Button1OnClick(Sender : TObject);
begin
MyFloat := StrToFloatDef(Edit1.Text, 15.28); {<== Error occurs here when Edit1.Text is empty}
end;

]

HOPE THAT HELPS!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.