Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

EConvertError - not a valid floating point value

Posted on 2006-05-02
5
Medium Priority
?
2,982 Views
Last Modified: 2008-02-07
Hey there,

I got this error message
-1,251 is not a valid floating point value

when I do this
  sBal := sBal + StrToFloat(ADOQ.FieldByName('Balance').AsString)

I think it has to do something with the comma, how can sort this... :-/
0
Comment
Question by:wildzero
  • 3
5 Comments
 
LVL 10

Author Comment

by:wildzero
ID: 16591820
I could do this

// Remove the , from the passed string
Function stripcom ( item : string ) : string;
begin
  result := AnsiReplaceText(item, ',', '');
end;

and call
 sBal := sBal + StrToFloat( stripcom(ADOQ.FieldByName('Balance').AsString) );

but it doesn't quiet feel right...
0
 
LVL 10

Author Comment

by:wildzero
ID: 16592186
>>but it doesn't quiet feel right...
I mean, im sure it could be done better (proper)
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 1000 total points
ID: 16592588

If the field is already a numeric tyoe (BCD, etc), then you should skip the .AsString and use something like .AsFloat instead. If the field really is a TString type, then the following routine could be used to clean the string up before conversion (it uses the locale info to perform the cleanup). A little more code, but much faster....

Regards,
Russell


function LocaleStrToDouble(S: String): Double;
var  lpszConvert:   PChar;
     cCurrency:     Char;
     szConvert:     String;
     dwLength:      Integer;
begin

  // Get source string
  lpszConvert:=PChar(S);

  // Check string
  if (lpszConvert = nil) then
     // Zero result
     result:=0
  else
  begin
     // Allocate source string
     SetLength(szConvert, Length(S));
     // Set parsed length
     dwLength:=0;
     // Strip thousands sep char in the string
     while (lpszConvert^ > #0) do
     begin
        // Check for thousands sep char
        if not(lpszConvert^ = ThousandSeparator) then
        begin
           // Copy char
           szConvert[Succ(dwLength)]:=lpszConvert^;
           // Push length
           Inc(dwLength);
        end;
        // Push next
        Inc(lpszConvert);
     end;
     // Set parsed length
     SetLength(szConvert, dwLength);
     // Convert to double
     Val(szConvert, result, dwLength);
     // Check conversion
     if (dwLength <> 0) then raise EConvertError.Create('Invalid floating point string!');
  end;

end;
0
 
LVL 7

Assisted Solution

by:kfoster11
kfoster11 earned 400 total points
ID: 16602036
use fieldbyname('').ascurrency
or
if the field is stored as a string in the database then change the field type if possible.
0
 
LVL 10

Author Comment

by:wildzero
ID: 16662500
Thanks guys =)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question