delphi 中 Int()和Trunc()函数都是取整数值
请问一下他们之间的区别是什么?
有没有特定用Int()或Trunc()的地方?

解决方案 »

  1.   

    function Int(X: Extended): Extended;//将实数的小数部分去掉
    function Trunc(X: Extended): Int64;//将实数变为整数
      

  2.   

    Delphi syntax:function Trunc(X: Extended): Int64;DescriptionIn 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. 也就是说Trunc直接取整 比如 X := trunc(5.6)  X := 5; X是Int64类型,是整数Delphi syntax:function Int(X: Extended): Extended;DescriptionIn Delphi code, Int returns the integer part of X; that is, X rounded toward zero. X is a real-type expression.Int也是取整 但是 X := Int(5.6) X := 5.0 X是Extended 还是一个浮点数
      

  3.   

    trunc不是四舍五入吧!!trunc和int函数都是取整int截去实数的小数部分,返回的是实数;
    trunc将实数变为整数,返回的是64位整数;
    都没有四舍五入,好像处理负数的时候不一样!
      

  4.   

    两个都是向零取整,区别可能就是返回值的差别了吧,一个是Int64,另一个没有类型限制。
      

  5.   

    function Int(X: Extended): Extended;//将实数的小数部分去掉 
    function Trunc(X: Extended): Int64;//将实数变为整数正确.
      

  6.   

    Int()返回的是实数
    Trunc()返回的是整数
    呵呵~~
      

  7.   

    round才是四舍五入最大的作用如楼上所说,看你要的什么类型
      

  8.   

    int(x)=x-frac(x)
    trunc(x)是system的,速度快(比Math中的floor快)
    老實說..到底int有什麼時候會用??除去了小數的浮點數,速度比整數慢很多,也沒有這種需要