I made this while experimenting with Delphi and changed it to run in Scar. I though it may be useful to someone, and thus it made its way here:
SCAR Code:
function RoundDec(number: extended; decimals: integer): extended;
begin
Result := Round(number * Pow(10, decimals)) / Pow(10, decimals);
end;
You can test it with this:
SCAR Code:
program New;
function RoundDec(number: extended; decimals: integer): extended;
begin
Result := Round(number * Pow(10, decimals)) / Pow(10, decimals);
end;
begin
Writeln(FloatToStr(RoundDec(1.23456789, 8)));
end.
And change the 8 to different numbers to see it in action.