是一个浮点数,返回值也是个浮点数)
范例:
var S, Temp: string; begin Str(Sqr(5.0):3:1, Temp); S := ''''5 squared is '''' + Temp + #13#10; Str(Sqrt(2.0):5:4, Temp); S := S + ''''The square root of 2 is '''' + Temp; MessageDlg(S, mtInformation, [mbOk], 0); end;
返回
函数名
Trunc
简要介绍:
Truncates a real number to an integer.(截取一个实数的整数部分)
所属单元:
System
定义:
function Trunc(X: Extended): Int64;
详细解释:
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.
范例:
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.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)); MessageDlg(S, mtInformation, [mbOk], 0); end;