fpspreadsheet: Avoid Banker's rounding (https://forum.lazarus.freepascal.org/index.php/topic,46104.0.html). Add unit tests for it.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7061 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-07-20 16:52:10 +00:00
parent 42ad68b2bc
commit d88d99a5a2
6 changed files with 118 additions and 5 deletions

View File

@@ -153,6 +153,8 @@ function TryStrToFloatAuto(AText: String; out ANumber: Double;
function TryFractionStrToFloat(AText: String; out ANumber: Double;
out AIsMixed: Boolean; out AMaxDigits: Integer): Boolean;
function Round(AValue: Double): Integer;
function cmToPts(AValue: Double): Double; inline;
function EMUToIn(AValue: Int64): Double; inline;
function EMUToMM(AValue: Int64): Double; inline;
@@ -1849,6 +1851,16 @@ begin
Result := true;
end;
{@@ ----------------------------------------------------------------------------
Special rounding function which avoids banker's rounding
-------------------------------------------------------------------------------}
function Round(AValue: Double): Integer;
begin
if AValue > 0 then
Result := trunc(AValue + 0.5)
else
Result := trunc(AValue - 0.5);
end;
{@@ ----------------------------------------------------------------------------
Excel's unit of row heights is "twips", i.e. 1/20 point.