saxon:decimal-divide

Decimal division with user-specified precision.

decimal-divide($arg1 as xs:decimal?, $arg2 as xs:decimal?, $precision as xs:integer) ➔ xs:decimal?

Arguments

 

$arg1

xs:decimal?

The numerator

 

$arg2

xs:decimal?

The denominator

 

$precision

xs:integer

The number of digits required in the result

Result

xs:decimal?

Namespace

http://saxon.sf.net/

Saxon availability

Requires Saxon-PE or Saxon-EE.

Notes on the Saxon implementation

Available since Saxon 8.0.

Details

This function performs a decimal division to a user-specified precision. The value of the first argument is divided by the second argument, and the result is returned to the number of decimal places indicated by the third argument. Specifically, if the third argument is N, then the result will be a multiple of ten to the power of minus N. The exact result is rounded towards zero.

Examples:

  • decimal-divide(100, 30, 2) returns 3.33

  • decimal-divide(100, 30, 4) returns 3.3333

  • decimal-divide(100, 30, 0) returns 3

  • decimal-divide(100, 3, -1) returns 30

  • decimal-divide(100, 700, 6) returns 0.142857

(The default for decimal division in Saxon using the div operator is to return max(18, s1, s2) decimal places in the result, where s1 is the scale of the first operand and s2 the scale of the second.)

The function returns an empty sequence if either operand is an empty sequence.