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( "tapered" )
local trunc = require( "trunc" )

t.is( 0, trunc( 0.2 ) )
t.is( 0, trunc( 0.7 ) )

t.is( 0, trunc( -0.2 ) )
t.is( 0, trunc( -0.7 ) )

t.done()

Inspired by