Name

Trunc Function

Syntax

function Trunc(X: Floating-point type): Int64;

Description

The Trunc function truncates a floating-point value by discarding the fractional part (round towards zero). Unlike Int, Trunc returns an integer result. Trunc is not a real function.

Tips and Tricks

  • The Trunc function temporarily sets the floating-point control word, then truncates the number, and restores the control word.

  • If X is an integer, the compiler eliminates the call to Trunc and simply returns X.

  • If X is a Variant, Delphi automatically converts it to a floating-point number and truncates it.

  • The compiler does not accept an Int64 argument, but there is no reason to call Trunc for Int64.

  • If X is infinity or NaN, Trunc reports runtime error 6 (EInvalidOp).

See Also

Int Function, Round Function

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.