1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function Arrondir(nombre : extended ; nbDecim : integer) : extended;
var
p10 : extended;
begin
{ 2 étant le cas le plus fréquent, on le traite directement }
if (nbDecim = 2) then
result := round(nombre * 100) / 100
else
begin
p10 := Power(10,nbDecim);
result := round(nombre * p10) / p10;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
X1, x2, d1: Extended;
begin
x1 := 10000000.2 ;
x2 := 10000000.1 ;
d1 := x1 - x2 ;
//ShowMessage(floatToStr(d1));
//ShowMessage(FormatFloat('0', StrToFloat(floatToStr(d1))));
//------- En utilisant la fonction ci-dessus ----------------//
Showmessage(floatToStr(arrondir(d1, 1))); //(0.099999999627,1)));
//------/ En utilisant la fonction ci-dessus ----------------//
//------- Ou bien SANS UTILISER la fonction ci-dessus -------//
ShowMessage(floatToStr(SimpleRoundTo(d1, -2)));
//------/ Ou bien SANS UTILISER la fonction ci-dessus -------//
end; |
Partager