Scalabium Software

SMReport Autogenerated
Knowledge for your independence'.
Home Delphi and C++Builder tips


#113: How can I round a number correctly?

From first times when was released a Borland Pascal, in sources was included a "bank" algorithm of number rounding.
For example,
Round(25.5) = 26
but
Round(26.5) = 26.

For banks or some other financial organizations this algorithm is good but in other type of calculations we want a standard rounding. For this tasks I use the own small function that I use instead standard:

function CorrectRound(x: Extended): LongInt;
begin
  Result := Trunc(x);
  if (Frac(x) >= 0.5) then
    Result := Result + 1;
end;


Published: January 7, 2001

See also
 
dBase Viewer
Word Web-stream
MAPIMail
Clarion to Text converter
SMExport suite
DBISAM Password Recovery
DBISAM Viewer
Paradox to MS Access converter
SMImport suite
Excel Web-stream
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2023, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMReport Autogenerated