Using round function I implemented the RoundTo function as in Delphi:

type
 TRoundToRange = -37..37;

function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;
var
 LFactor: Double;
begin
 LFactor := IntPower(10, ADigit);
 Result := Round(AValue / LFactor) * LFactor;
end;

In Delphi RoundTo has a known bug (http://qc.borland.com/wc/qcmain.aspx?d=8070).
And in freepascal (Windows) I noticed the same behavior.
In order to respect the banker's rounding we must obtain:
RoundTo(1.235, -2) ->1.24
RoundTo(1.245, -2) -> 1.24

But in reality:
RoundTo(1.235, -2) ->1.24
RoundTo(1.245, -2) -> 1.25

I didn't test it on Linux yet.
It is a known bug?
a.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to