Difference between revisions of "Math.round"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
Line 7: Line 7:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
(number) = math.round(v)
 
(number) = math.round(v)
</source>
+
</syntaxhighlight>
  
 
For example, the value 5.8 returns 6.
 
For example, the value 5.8 returns 6.

Latest revision as of 14:31, 13 July 2023

Available since: Gideros 2022.1
Class: math

Description

Returns the integer with the smallest difference between it and the given number.

(number) = math.round(v)

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