Skip to content

Trunc ​

Trunc removes any decimals and returns aValue truncated to its own integer value.

Minus (negative) signs are accepted and also returned, but separating commas and any other non-numeric characters must be stripped out before being passed into the Trunc function.

Trunc performs a similar function to Int. However, Int returns a floating-point number. Please refer to Int for more information.

Also refer to the Round series of functions, for a function that rounds decimals up and/or down.

Declaration: Function Trunc( aValue : Extended) : Integer

Several examples follow.

pascal
Procedure OnMapEvent(var Value:variant);
var aNumber : integer;
begin
  Value :=  Trunc(19.234589);          // returns 19
  Value :=  Trunc(-75339.46);          // returns -75339

  aNumber :=  Trunc(4567.234589);      // returns 4567
  LogInfo(IntToStr(aNumber));
  aNumber :=  Trunc(-5232.46);         // returns -5232
  LogInfo(IntToStr(aNumber));
  aNumber :=  Trunc(1234.56);          // returns 1234
  LogInfo(IntToStr(aNumber));

end;