From Clomosy Docs

No edit summary
No edit summary
Line 1: Line 1:
function Round(const Number Extended):Int64;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function Round(X: Real): Int64;
</div>


The Round function rounds a floating point Number to an Integer value. The rounding uses Bankers rules, where an exact half value causes a rounding to an even number:
It is used to round decimal numbers to the nearest whole number. If the decimal part is greater than 0.5, it rounds up; if it is less than 0.5, it rounds down. If the given number is exactly halfway (0.5) between two numbers, the result is always the even number.<br>
   
   
12.4 rounds to 12
12.4 rounds to 12<br>
12.5 rounds to 12 // Round down to even
12.5 rounds to 12 // Round down to even<br>
12.6 rounds to 13
12.6 rounds to 13<br>
13.4 rounds to 13<br>
13.4 rounds to 13
13.5 rounds to 14 // Round up to even<br>
13.5 rounds to 14 // Round up to even
13.6 rounds to 14<br>
13.6 rounds to 14


'''Example:'''<br>
<b>Example</b><br>
:'''Base Syntax'''
<b>TRObject Syntax</b><br>
  var
<pre>
    numberFloat : Float;
var
 
  numberFloat : Float;
  begin
 
{
    numberFloat := 15.50;   
    ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr('''Round'''(numberFloat)));
  numberFloat = 15.50; 
 
  ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr(Round(numberFloat)));
  end;
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  numberFloat : Float;
begin
  numberFloat := 15.50;   
  ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr(Round(numberFloat)));
end;
</pre>
 
<b>Output:</b><br>
<div class="alert alert-success" role="alert" data-bs-theme="light">
Round(15,5) = 16
</div>


:'''TRObject Syntax'''
<h2> See Also </h2>
  var
* [[System_Library#Math_Functions | Math Functions]]
    numberFloat : Float;
 
  {
 
    numberFloat = 15.50; 
    ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr('''Round'''(numberFloat)));
 
  }
'''Output:'''<br>
Round(15,5) = 16

Revision as of 12:42, 7 October 2024

It is used to round decimal numbers to the nearest whole number. If the decimal part is greater than 0.5, it rounds up; if it is less than 0.5, it rounds down. If the given number is exactly halfway (0.5) between two numbers, the result is always the even number.

12.4 rounds to 12
12.5 rounds to 12 // Round down to even
12.6 rounds to 13
13.4 rounds to 13
13.5 rounds to 14 // Round up to even
13.6 rounds to 14

Example
TRObject Syntax

 var
   numberFloat : Float;
 
 {
 
   numberFloat = 15.50;  
   ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr(Round(numberFloat)));
 
 }

Base Syntax

 var
   numberFloat : Float;
 
 begin
 
   numberFloat := 15.50;  
   ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr(Round(numberFloat)));
 
 end;

Output:

See Also