trunc
function trunc( num ) --> i
Description
Truncates a number to an integer by removing the fractional part of the number.
Parameters
- num
-
The number that should be truncated.
Return Values
- i
-
Integer number representation of the assigned number value.
Code
--ZFUNC-trunc-v1 local function trunc( num ) --> i if ( num > 0 ) then return math.floor( num ) else return math.ceil( num ) end end return trunc
Examples
local t = require( "taptest" ) local trunc = require( "trunc" ) t( trunc( 1.2 ), 1 ) t( trunc( 1.7 ), 1 ) t( trunc( -2.2 ), -2 ) t( trunc( -2.7 ), -2 ) t()