Delphi Sources

Проверить, является ли число вещественным



Оформил: DeeCo

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;

Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте