Node:Trunc, Next:Truncate, Previous:True, Up:Reference
function Trunc (x: Real): Integer;
Trunc returns the integer part of a floating point number as
an integer. Use Int to get the integer part as
a floating point number.
Trunc is defined in ISO 7185 Pascal and supported
by all known Pascal variants.
program TruncDemo;
begin
WriteLn (Frac (12.345) : 1 : 5); { 0.34500 }
WriteLn (Int (12.345) : 1 : 5); { 12.00000 }
WriteLn (Round (12.345) : 1); { 12 }
WriteLn (Trunc (12.345) : 1); { 12 }
WriteLn (Frac (-12.345) : 1 : 5); { -0.34500 }
WriteLn (Int (-12.345) : 1 : 5); { -12.00000 }
WriteLn (Round (-12.345) : 1); { -12 }
WriteLn (Trunc (-12.345) : 1); { -12 }
WriteLn (Frac (12.543) : 1 : 5); { 0.54300 }
WriteLn (Int (12.543) : 1 : 5); { 12.00000 }
WriteLn (Round (12.543) : 1); { 13 }
WriteLn (Trunc (12.543) : 1); { 12 }
WriteLn (Frac (-12.543) : 1 : 5); { -0.54300 }
WriteLn (Int (-12.543) : 1 : 5); { -12.00000 }
WriteLn (Round (-12.543) : 1); { -13 }
WriteLn (Trunc (-12.543) : 1); { -12 }
end.