如何将real转换为integer

SunwW 2004-07-10 05:04:30
怎么全文检索老是不能用?记不得怎么转换real为integer
...全文
238 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
song317 2004-07-10
  • 打赏
  • 举报
回复
Trunc function
Truncates a real number to an integer.
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;
function Trunc(X: Extended): Int64;

Description

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.
_____________________________

Int function
Returns the integer part of a real number.
var

R: Real;
begin
R := Int(123.456); { 123.0 }
R := Int(-123.456); { -123.0 }
end;
function Int(X: Extended): Extended;

Description

Int returns the integer part of X; that is, X rounded toward zero. X is a real-type expression.


Round function
Returns the value of X rounded to the nearest whole number.
var

S, T: string;

begin

Str(1.4:2:1, T);
S := T + ' rounds to ' + IntToStr(Round(1.4)) + #13#10;
Str(1.5:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(1.5)) + #13#10;
Str(-1.4:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(-1.4)) + #13#10;
Str(-1.5:2:1, T);
S := S + T + ' rounds to ' + IntToStr(Round(-1.5));
MessageDlg(S, mtInformation, [mbOk], 0);
end;
______________________________________

function Round(X: Extended): Int64;

Description

The Round function rounds a real-type value to an integer-type value.

X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is always the even number.

If the rounded value of X is not within the Int64 range, a run-time error is generated, which can be handled using the EInvalidOp exception.
creativepeter 2004-07-10
  • 打赏
  • 举报
回复
ShowMessage(IntToStr(Trunc(temp)));//验证
所以可以用Trunc(X)函数

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧