trunc[]

Truncate value.

Rounds toward zero, returning the nearest integral value that is not larger in magnitude than x.

The trunc[] function is a function that returns the truncated integer value of a given number. It removes the decimal part of the number without rounding it up or down, effectively chopping off anything after the decimal point. The input can be a number of any type that can be converted to a float, and the output will be an integer.

For example, trunc[3.14159] would return 3, and trunc[-2.5] would return -2.

It is commonly used in mathematical calculations and in situations where you want to remove the decimal part of a number without rounding it. It can also be used for type casting a float to int.

Syntax

trunc[x]

Parameters

x Number to truncate.
Return Value The nearest integral value that is not larger in magnitude than x.

Examples

#<result> = trunc[2.3]
(print,#<result>)

result: 2


#<result> = trunc[-2.3]
(print,#<result>)

result: -2

See also

round, floor, ceil