(Gast)
n/a Beiträge
|
AW: Ganze Zahl immer auf nächste 50 runden?
26. Feb 2017, 20:30
SetRoundMode(rmNearest);
http://docwiki.embarcadero.com/CodeE...ndMode_(Delphi)
Zwischenschritte: Div 100, Multi 100
Delphi-Quellcode:
uses ...System.Math,...
procedure TForm1.ButtonClick(Sender: TObject);
var
OldRM: TRoundingMode;
TestValue: Real;
procedure RecordRound(const TextStr: String; Value: Real);
{ Calls Round() and shows its value in the Memo control.
Affected by the value passed to SetRoundMode(). }
var RetVal: Real;
begin
RetVal := Round(Value);
Memo1.Lines.Add(Format('%-15s RetVal=%f', [TextStr, RetVal]));
end;
begin
OldRM := GetRoundMode; { Save the original setting for the Round Mode }
TestValue := 5.7; { First test value }
Memo1.Lines.Add(Format('Value=%f', [TestValue]));
SetRoundMode(rmDown);
RecordRound('rmDown #1', TestValue);
SetRoundMode(rmUp);
RecordRound('rmUp #2', TestValue);
SetRoundMode(rmNearest);
RecordRound('rmNearest #3', TestValue);
SetRoundMode(rmTruncate);
RecordRound('rmTruncate #4', TestValue);
Memo1.Lines.Add(''); { Adds a blank line to the memo }
TestValue := -1.3; { Second test value }
Memo1.Lines.Add(Format('Value=%f', [TestValue]));
SetRoundMode(rmDown);
RecordRound('rmDown #5', TestValue);
SetRoundMode(rmUp);
RecordRound('rmUp #6', TestValue);
SetRoundMode(rmNearest);
RecordRound('rmNearest #7', TestValue);
SetRoundMode(rmTruncate);
RecordRound('rmTruncate #8', TestValue);
SetRoundMode(OldRM); { Restore the original Rounding Mode }
end;
|
|
Zitat
|