Algorithm Math Delphi

function RoundD(x: Extended; d: Integer): Extended;
// RoundD(123.456, 0) = 123.00
// RoundD(123.456, 2) = 123.46
// RoundD(123456, -3) = 123000
var
n: Extended;
begin
n := Power(10, d);
x := x * n;
Result := (Int(x) + Int(Frac(x) * 2)) / n;
end;