G'Day,
Given the code below. If the param values are as follows:
AnoBallsPerOver = 4
AnoNoBalls = 0
AoverNotation = 159.2
The expected result is: (159 * 4) + 2 = 638. However when I trace the code I
see the following:
//From Overs
iBalls := Trunc(Int(AOverNotation) * ANoBallsPerOver);
Gives 636 as expected. Then it starts getting confusing:
Frac(AOverNotation) gives 0.2 (As expected)
Frac(AOverNotation) * 10 gives 2 (As expected)
Trunc(Frac(AOverNotation) * 10) gives 1 !!!!! Why is that?
Can someone point me in the right direction here please?
TIA
function TfrmImportHistoricInfo.Calc_BallsFromOvers(ANoBallsPerOver :
SmallInt; ANoNoBalls : SmallInt; AOverNotation : double) : SmallInt;
////////////////////////////////////////////////////////////////////////////
////
// PURPOSE: Calculates the number of balls bowled from the number of overs
specified
const
PROC_NAME = 'TfrmImportHistoricInfo.Calc_BallsFromOvers';
ERR_MSG = 'I was unable to determine the number of balls bowled';
var
iBalls : SmallInt;
begin
//Default behavior
result := -1;
try
iBalls := 0;
//From Overs
iBalls := Trunc(Int(AOverNotation) * ANoBallsPerOver);
//From Balls
iBalls := iBalls + Trunc(Frac(AOverNotation) * 10);
//No Balls
iBalls := iBalls + ANoNoBalls;
//Return it
result := iBalls;
//result := Trunc((Int(AOverNotation) * ANoBallsPerOver) +
(Frac(AOverNotation) * 10)) + ANoNoBalls;
except
on E : Exception do
Handle_AppExceptions(UNIT_NAME, PROC_NAME, ERR_MSG, E.Message,
SystemSettings.ViewForComposite);
end;
end;
-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems [www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"