呵呵,看看下面你就明:在onkeypress中写入以下代码:IF NOT(KEY IN ['0'..'9','.',#8]) THEN KEY:=#0;
TO LKJ99(阳江in深圳,路在何方...) : 小数点要单独处理的, if not (Key in ['0'..'9', #8, #9, #13]) then begin if Key = '.' then begin //对小数点的处理,自己写。 end else begin Key := #0; end; end;
Function PLstrtoFloat(ss:string):Extended; var plst,pls,plss,plsss:string; NOdian,NOjianhao,NOjiahao:boolean; plf:double; i:integer; begin plss:=''; NOdian:=true; NOjianhao:=true; NOjiahao:=true; pls:=trim(ss); for i:=1 to length(pls) do begin plst:=copy(pls,i,1); if (plst='0') or (plst='1') or (plst='2') or (plst='3') or (plst='4') or (plst='5') or (plst='6') or (plst='7') or (plst='8') or (plst='9') or ((plst='.') and Nodian) or ((plst='+') and Nojiahao) or ((plst='-') and Nojianhao) then plss:=plss+plst; if (plst='.') then Nodian :=false; if (plst='+') then Nojiahao :=false; if (plst='-') then Nojianhao :=false; end; Plsss:=copy(plss,1,1); plst:=''; if (length(plss)>=2) then begin for i:=2 to length(plss) do Begin plst:=copy(plss,i,1); if (plst<>'+') and (plst<>'-') then plsss:=plsss+plst; End; plf:=strtofloat(plsss); end else begin if (plss='-') Or (plss='+') Or (plss='') then plf:=0 else plf:=strtofloat(plss); end; result:=plf; end;
KEY:=#0;
小数点要单独处理的,
if not (Key in ['0'..'9', #8, #9, #13]) then
begin
if Key = '.' then
begin
//对小数点的处理,自己写。
end
else
begin
Key := #0;
end;
end;
try
strtofloat(edit1.text);
except
showmessage('不是数字');
end;
本人水平低,问一下:#9代表什么?
var
plst,pls,plss,plsss:string;
NOdian,NOjianhao,NOjiahao:boolean;
plf:double;
i:integer;
begin
plss:='';
NOdian:=true;
NOjianhao:=true;
NOjiahao:=true; pls:=trim(ss);
for i:=1 to length(pls) do
begin
plst:=copy(pls,i,1);
if (plst='0') or (plst='1') or (plst='2') or
(plst='3') or (plst='4') or (plst='5') or
(plst='6') or (plst='7') or (plst='8') or
(plst='9') or
((plst='.') and Nodian) or
((plst='+') and Nojiahao) or
((plst='-') and Nojianhao)
then plss:=plss+plst;
if (plst='.') then Nodian :=false;
if (plst='+') then Nojiahao :=false;
if (plst='-') then Nojianhao :=false;
end;
Plsss:=copy(plss,1,1);
plst:='';
if (length(plss)>=2) then
begin
for i:=2 to length(plss) do
Begin
plst:=copy(plss,i,1);
if (plst<>'+') and (plst<>'-') then plsss:=plsss+plst;
End;
plf:=strtofloat(plsss);
end
else
begin
if (plss='-') Or (plss='+') Or (plss='') then plf:=0
else plf:=strtofloat(plss);
end;
result:=plf;
end;
numedit:=PLstrtoFloat(edi1.text);//注:PLstrtoFloat没有处理科学记数法,即e或E,你可以自己加上
numedit为float类型
testString := '输入的内容是数字'
try
strtofloat(edit1.text);
except
testString := '输入的内容不是数字';
end;
showmessage(testString)