You are overcomplicating matters. You can simply use Round
:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
C: Currency;
begin
C := 999999989000.4;
Writeln(Round(C));
C := 999999989000.5;
Writeln(Round(C));
C := 999999989000.6;
Writeln(Round(C));
C := 999999989001.4;
Writeln(Round(C));
C := 999999989001.5;
Writeln(Round(C));
C := 999999989001.6;
Writeln(Round(C));
Readln;
end.
which outputs
999999989000
999999989000
999999989001
999999989001
999999989002
999999989002
If you don't want banker's rounding, and you really do want your Trunc
logic then you do need to write your own function. But the problem with your function is that it was truncating to 32 bit integer. Make the function return a 64 bit integer:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, Math;
var
C: Currency;
function MyRound(const Value: Currency): Int64;
begin
if Value > 0 then
result := Trunc(Value + 0.5)
else
result := Trunc(Value - 0.5);
end;
begin
C := 999999989000.4;
Writeln(MyRound(C));
C := 999999989000.5;
Writeln(MyRound(C));
C := 999999989000.6;
Writeln(MyRound(C));
C := 999999989001.4;
Writeln(MyRound(C));
C := 999999989001.5;
Writeln(MyRound(C));
C := 999999989001.6;
Writeln(MyRound(C));
Readln;
end.
999999989000
999999989001
999999989001
999999989001
999999989002
999999989002