Comunque se l'effetto voluto è un euro-arrotondatore questo è quanto uso, con tanto di tristissime patch per (s)vista e certi problemini di stabilità numerica in prossimità dello zero, soprattutto per processori AMD, con tanto di "riprova" (!!!!!!)
codice:
function EuroArrotonda(x:double):double;
var
myx:double;
euro2:double;
function EuroArrotonda2(x:double):double;
var
testostringa:string;
posizionepunto:integer;
ultimacifra:integer;
parteintera:string;
i:integer;
parteinterainteger:integer;
begin
result:=x;
testostringa:=floattostr(x*100.0);
testostringa:=stringreplace(testostringa,'.',',',[rfreplaceall]);
posizionepunto:=pos(',',testostringa);
if posizionepunto>0 then
if posizionepunto<length(testostringa) then
begin
ultimacifra:=strtoint(testostringa[posizionepunto+1]);
parteintera:='';
for i:=1 to posizionepunto-1 do
parteintera:=parteintera+testostringa[i];
if ultimacifra>=5 then
parteinterainteger:=strtoint(parteintera)+1
else
parteinterainteger:=strtoint(parteintera);
result:=parteinterainteger / 100.0;
end;
end;
begin
// fix strano per vista. mah....
if x<10E-9 then
begin
// myshowmessage('Arrotondo a zero '+floattostr(x));
x:=0;
end;
if x>10E15 then
begin
//myshowmessage('Valore eccessivo => arrotondo a zero '+floattostr(x));
x:=0;
end;
myX:=x;
try
x:=x*100.0;
//vecchio x := Trunc(X) + Trunc (Frac(X) * 2);
if abs(Frac(x)-0.5)<0.0000001 then
x := Trunc(X) + 1
else
x := Trunc(X) + Trunc (Frac(X) +Frac(X));
x:=x/100.0;
except
//frmgurumeditation.i_messaggio:='Euroarrotonda 19539 '+floattostr(myX);
end;
result:=x;
if myX>=0.000001 then
// accidenti è una situazione numericamente instabile, verifica
begin
euro2:=euroarrotonda2(myx);
if floattostr(x)<>floattostr(euro2) then
begin
//frmgurumeditation.i_messaggio:='Euroarrotonda: '+floattostr(myx)+' a1= '+floattostr(x)+' <> a2='+floattostr(euro2);
end;
end;
end;