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
|
procedure TForm2.Button2Click(Sender: TObject);
var r : real;
function rdTrunc(rr : real):real;
begin
Result:=trunc(rr*10) /10;
// ou Result:=int(rr*10)/10
end;
function rdRound(rr : real):real;
begin
Result:=Round(rr*10)/10;
end;
begin
r:=143.64 +0.04;
memo2.Lines.add(' r = 143.64 +0.04');
memo2.Lines.add(format('Roundto -1 %3.2f',[Roundto(r,-1)]));
SetRoundMode(TroundingMode.rmNearest);
memo2.Lines.add(format('SimpleRoundto roundmode rmnearest %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmDown);
memo2.Lines.add(format('SimpleRoundto roundmode rmdown %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmUp);
memo2.Lines.add(format('SimpleRoundto roundmode rmup %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmTruncate);
memo2.Lines.add(format('SimpleRoundto roundmode rmtruncate %3.2f',[SimpleRoundto(r,-1)]));
memo2.Lines.add(Format('rdRound %3.2f',[rdRound(r)]));
memo2.Lines.add(Format('rdTrunc %3.2f',[rdTrunc(r)]));
r:=359.88-0.02;
memo2.Lines.Add('');
memo2.Lines.add(' r = 359.88-0.02');
memo2.Lines.add(format('Roundto -1 %3.2f',[Roundto(r,-1)]));
SetRoundMode(TroundingMode.rmNearest);
memo2.Lines.add(format('SimpleRoundto roundmode rmnearest %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmDown);
memo2.Lines.add(format('SimpleRoundto roundmode rmdown %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmUp);
memo2.Lines.add(format('SimpleRoundto roundmode rmup %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmTruncate);
memo2.Lines.add(format('SimpleRoundto roundmode rmtruncate %3.2f',[SimpleRoundto(r,-1)]));
memo2.Lines.add(Format('rdRound %3.2f',[rdRound(r)]));
memo2.Lines.add(Format('rdTrunc %3.2f',[rdTrunc(r)]));
r:=106.57 -0.03;
memo2.Lines.Add('');
memo2.Lines.add(' r = 106.57 -0.03');
memo2.Lines.add(format('Roundto -1 %3.2f',[Roundto(r,-1)]));
SetRoundMode(TroundingMode.rmNearest);
memo2.Lines.add(format('SimpleRoundto roundmode rmnearest %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmDown);
memo2.Lines.add(format('SimpleRoundto roundmode rmdown %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmUp);
memo2.Lines.add(format('SimpleRoundto roundmode rmup %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmTruncate);
memo2.Lines.add(format('SimpleRoundto roundmode rmtruncate %3.2f',[SimpleRoundto(r,-1)]));
memo2.Lines.add(Format('rdRound %3.2f',[rdRound(r)]));
memo2.Lines.add(Format('rdTrunc %3.2f',[rdTrunc(r)]));
r:=1829;
memo2.Lines.Add('');
memo2.Lines.add(' r = 1829');
memo2.Lines.add(format('Roundto -1 %3.2f',[Roundto(r,-1)]));
SetRoundMode(TroundingMode.rmNearest);
memo2.Lines.add(format('SimpleRoundto roundmode rmnearest %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmDown);
memo2.Lines.add(format('SimpleRoundto roundmode rmdown %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmUp);
memo2.Lines.add(format('SimpleRoundto roundmode rmup %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmTruncate);
memo2.Lines.add(format('SimpleRoundto roundmode rmtruncate %3.2f',[SimpleRoundto(r,-1)]));
memo2.Lines.add(Format('rdRound %3.2f',[rdRound(r)]));
memo2.Lines.add(Format('rdTrunc %3.2f',[rdTrunc(r)]));
r:=1936.51 +0.01;
memo2.Lines.Add('');
memo2.Lines.add(' r = 1936.51 +0.01');
memo2.Lines.add(format('Roundto -1 %3.2f',[Roundto(r,-1)]));
SetRoundMode(TroundingMode.rmNearest);
memo2.Lines.add(format('SimpleRoundto roundmode rmnearest %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmDown);
memo2.Lines.add(format('SimpleRoundto roundmode rmdown %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmUp);
memo2.Lines.add(format('SimpleRoundto roundmode rmup %3.2f',[SimpleRoundto(r,-1)]));
SetRoundMode(TroundingMode.rmTruncate);
memo2.Lines.add(format('SimpleRoundto roundmode rmtruncate %3.2f',[SimpleRoundto(r,-1)]));
memo2.Lines.add(Format('rdRound %3.2f',[rdRound(r)]));
memo2.Lines.add(Format('rdTrunc %3.2f',[rdTrunc(r)]));
end; |
Partager