math:trunc

math:trunc(
   $arg as numeric?,
   [$n as xs:integer]
) as numeric?

Summary

Returns the number truncated to a certain number of decimal places. If type of $arg is one of the four numeric types xs:float, xs:double, xs:decimal or xs:integer the type of the result is the same as the type of $arg. If the type of $arg is a type derived from one of the numeric types, the result is an instance of the base numeric type.

For xs:float and xs:double arguments, if the argument is positive infinity, then positive infinity is returned. If the argument is negative infinity, then negative infinity is returned. If the argument is positive zero, then positive zero is returned. If the argument is negative zero, then negative zero is returned.

Parameters
arg A numeric value to truncate.
n The numbers of decimal places to truncate to. The default is 0. Negative values cause that many digits to the left of the decimal point to be truncated.

Example

math:trunc(125.815)	returns 125
math:trunc(125.815, 0)	returns 125
math:trunc(125.815, 1)	returns 125.8
math:trunc(125.815, 2)	returns 125.81
math:trunc(125.815, 3)	returns 125.815
math:trunc(-125.815, 2)	returns -125.81
math:trunc(125.815, -1)	returns 120
math:trunc(125.815, -2)	returns 100
math:trunc(125.815, -3)	returns 0
Powered by MarkLogic Server | Terms of Use | Privacy Policy