Difference between revisions of "Math.round"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2022.1<br/> '''Class:''' math<br/> === Description === Returns the integer with the smallest difference between it and the given...")
 
m (Text replacement - "<source" to "<syntaxhighlight")
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Returns the integer with the smallest difference between it and the given number.
 
Returns the integer with the smallest difference between it and the given number.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(number) = math.round(v)
 
(number) = math.round(v)
 
</source>
 
</source>

Revision as of 14:28, 13 July 2023

Available since: Gideros 2022.1
Class: math

Description

Returns the integer with the smallest difference between it and the given number. <syntaxhighlight lang="lua"> (number) = math.round(v) </source>

For example, the value 5.8 returns 6.

For values like 0.5 that are equidistant to two integers, the value with the greater difference between it and zero is chosen. In other words, the function rounds away from zero: 0.5 rounds to 1; -0.5 rounds to -1.

Parameters

v: (number) value to round

Return values

Returns (number) rounding result