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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
lw: TListView;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
uses
Math;
{$R *.dfm}
function ArrondiParDefaut( Value: Double; Prec: Integer): Double;
var
rmSave: TFPURoundingMode;
begin
rmSave := GetRoundMode;
try
SetRoundMode(rmDown);
Result := RoundTo(Value, Prec);
finally
SetRoundMode(rmSave);
end;
End;
function ArrondiParExces( Value: Double; Prec: Integer): Double;
var
rmSave: TFPURoundingMode;
begin
rmSave := GetRoundMode;
try
SetRoundMode(rmUp);
Result := RoundTo(Value, Prec);
finally
SetRoundMode(rmSave);
end;
End;
function ArrondiParTronquage( Value: Double; Prec: Integer): Double;
var
rmSave: TFPURoundingMode;
begin
rmSave := GetRoundMode;
try
SetRoundMode(rmTruncate);
Result := RoundTo(Value, Prec);
finally
SetRoundMode(rmSave);
end;
End;
function ArrondiPlusProche( Value: Double; Prec: Integer): Double;
var
rmSave: TFPURoundingMode;
begin
rmSave := GetRoundMode;
try
SetRoundMode(rmTruncate);
Result := RoundTo(Value, Prec);
finally
SetRoundMode(rmSave);
end;
End;
procedure TForm1.Button1Click(Sender: TObject);
const
tab: array[0..3] of Double = (-25.255,-25.250,25.250,25.255);
var
I: integer;
begin
for I := Low(tab) to High(tab) do
begin
with lw.Items.Add do
begin
Caption := Format('%g', [tab[I]]);
SubItems.Add(Format('%g', [ArrondiParExces(tab[I],-2)]));
SubItems.Add(Format('%g', [ArrondiParDefaut(tab[I],-2)]));
SubItems.Add(Format('%g', [ArrondiPlusProche(tab[I],-2)]));
SubItems.Add(Format('%g', [ArrondiParTronquage(tab[I],-2)]));
end;
end;
End;
end. |
Partager