|
unit LeggiNumeri;
interface
function tasto(fr:string; t:char):string;
function ANumero(fr:string; fallito:double=0.0):double;
function AStringa(x:double; cif:word=0; dec:word=0):string;
function secondi:double;
implementation
uses sysutils;
function VerificaVirgola(fr:string):boolean;
var ch:boolean;
i:word;
begin
i:=1;
ch:=true;
while i<=length(fr) do
begin
if (fr[i]=',') or (fr[i]='.') then ch:=false;
i:=i+1;
end;
VerificaVirgola:=ch;
end;
function tasto(fr:string; t:char):string;
begin
case t of
'1'..'9': fr:=fr+t;
'0' : begin
if fr<>'' then fr:=fr+t;
end;
',', '.':begin
if VerificaVirgola(fr) then fr:=fr + ',';
if fr[1]=',' then fr:='0'+fr;
end;
'-' :begin
if fr='' then fr:=''
else
begin
if fr[1]='-' then delete(fr, 1, 1)
else fr:='-' + fr;
end;
end;
char(8) :begin
delete(fr, length(fr), 1);
end;
end;
tasto:=fr;
end;
function ANumero(fr:string; fallito:double=0.0):double;
var errore:integer;
x:double;
begin
val(fr, x, errore);
if errore>0 then x:=fallito;
ANumero:=x;
end;
function AStringa(x:double; cif:word=0; dec:word=0):string;
var risultato:string;
begin
str(x:cif:dec, risultato);
AStringa:=risultato;
end;
function secondi:double;
var h,m,s,cs:word;
begin
DecodeTime(Time, h,m,s,cs);
secondi:=3600.0*h + 60.0*m + s + 0.001*cs;
end;
end.
|
|