Truncates a real number to an integer.
function Trunc(X: Extended): Int64;
Int64 Trunc(Extended X);
In Delphi code, the Trunc function truncates a real-type value to an integer-type value. X is a real-type expression. Trunc returns an Int64 value that is the value of X rounded toward zero.
If the truncated value of X is not within the Int64 range, an EInvalidOp exception is raised.
Delphi Examples:
{ This example demonstrates how the Trunc function operates on various real numbers. } procedure TForm1.Button1Click(Sender: TObject); var S, T: string; begin Str(1.4:2:1, T); S := T + ' Truncs to ' + IntToStr(Trunc(1.4)) + #13#10; Str(1.5:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(1.5)) + #13#10; Str(1.6:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(1.6)) + #13#10; Str(-1.4:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.4)) + #13#10; Str(-1.5:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.5)) + #13#10; Str(-1.6:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.6)) + #13#10; Str(2.5:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(2.5)) + #13#10; Str(-2.5:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(-2.5)) + #13#10; Str(-2.6:2:1, T); S := S + T + ' Truncs to ' + IntToStr(Trunc(-2.6)); MessageDlg(S, mtInformation, [mbOk], 0, mbOk); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|