Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StrToFloat fails on valid strings

Status
Not open for further replies.

dubz

Programmer
Apr 8, 2002
1
AU
Hi,

I've written an app that receives real time stock price information via TCP/IP. The app receives strings in the form '5.9300000000000000e+02' and attempts to convert them to floating point numbers using the Delphi function
'StrToFloat'.

In the live version of the application, several thousands of these conversions were performed successfully. In the newest development version, I have integrated a third party component called UCalc ( which does some formula parsing. Since I integrated this component, the StrToFloat function fails occasionally on what look like valid strings. When a conversion fails, I catch the exception, and log the offending string to a text file. From here, I cut and paste the string into a harness

application and attempt to convert it again. It succeeds. I'm satisfied that the string represents a valid floating point number.

I have discussed the problem with the author of UCalc, and we're trying a few things, but nothing seems to work. I was wondering if you guys had any ideas on what the problem is?

Here's the offending code:

try
frmLog.LogMessage('Word: ' + IntToStr(Default8087CW));
BestBid := StrToFloat(BestBidStr);
except
on E: EConvertError do
begin
frmLog.LogMessage('Length of BidStr is ' + IntToStr (Length(BestBidStr)));
frmLog.LogMessage('ODF Conversion Error: ' + BestBidStr);
end;
end;

... and here's the log file:

Word: 4914
Length of BidStr is 22
ODF Conversion Error: 1.2700000000000000e+02

As you can see, there are no UCalc specific functions to be seen - I only bring it up because it's really the only change between the live and development versions.

Any suggestions greatly appreciated.

gleNN
 
In the old days when I used pascal when I send the output of a real number to screen, it showed up like '5.9300000000000000e+02' . To me it looks like you are already getting a real (or float) number in scientific notation. There is no need to convert to float. Use BestBid := BestBidStr;

Regards S. van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top