Mega Code Archive

 
Categories / Delphi / Examples
 

Validate a float number

Title: validate a float number? function StrIsReal(AString: string): Boolean; var I: Extended; Code: Integer; begin Val(AString, I, Code); Result := Code = 0; end; procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text := '123.222'; if StrIsReal(Edit1.Text) then ShowMessage('Valid float number! G ltige Gleitkommazahl!'); end; // In Delphi 6, there is a TryStrToFloat function // In Delphi6 gibt's auch eine TryStrToFloat Funktion procedure TForm1.Button1Click(Sender: TObject); var s: string; f: double; begin s := '123.222'; if TryStrToFloat(s, f) then ShowMessage('Ok!') else ShowMessage('No valid float number!'); end;