From Clomosy Docs
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
<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> | |||
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 | |||
<b>Example</b><br> | |||
:'''Base Syntax | <b>TRObject Syntax</b><br> | ||
<pre> | |||
var | |||
numberFloat : Float; | |||
{ | |||
numberFloat = 15.50; | |||
ShowMessage('Round('+FloatToStr(numberFloat)+') = '+FloatToStr(Round(numberFloat))); | |||
} | |||
</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> | |||
<h2> See Also </h2> | |||
* [[System_Library#Math_Functions | Math Functions]] | |||
Revision as of 12:42, 7 October 2024
function Round(X: Real): Int64;
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:
Round(15,5) = 16