Loading TOC...


   $arg as Number?,
   [$n as Number]
) as Number?


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.

$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.


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

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.