Object

org.apache.daffodil.dpath

DivDecimal

Related Doc: package dpath

Permalink

object DivDecimal extends NumericOp with Product with Serializable

Division with rounding for decimals

About the rounding.

Without rounding specified here, you can get an java arithmetic exception Specifically:

java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.

What's questionable here, is to what number of fraction digits it will round. That can be specified also as an argument to divide(), but we have no information here (or anywhere really) about what precision is desired. So we're omitting that and just saying "round it".

Really, there's no rounding scale/precision until we're ready to represent the number in a string. In this case we're not. We're in the middle of an expression, just happen to have two BigDecimal operands, and we're dividing them, which should produce a BigDecimal result.

DFDL expressions are supposed to be consistent with XPath, so we look there for suggestions. The XPath spec https://www.w3.org/TR/xpath-functions-3/#op.numeric says it is implementation defined.

For xs:decimal values, let N be the number of digits of precision supported by the implementation, and let M (M <= N) be the minimum limit on the number of digits required for conformance (18 digits for XSD 1.0, 16 digits for XSD 1.1). Then for addition, subtraction, and multiplication operations, the returned result should be accurate to N digits of precision, and for division and modulus operations, the returned result should be accurate to at least M digits of precision. The actual precision is ·implementation-defined·. If the number of digits in the mathematical result exceeds the number of digits that the implementation retains for that operation, the result is truncated or rounded in an ·implementation-defined· manner

In our case, the implementation does what the JVM and java libraries do when divide() is called with two arguments the second of which specifies to round half-up.

Linear Supertypes
Serializable, Serializable, Product, Equals, NumericOp, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DivDecimal
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. NumericOp
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. implicit def BigDecimalToJBigDecimal(bd: BigDecimal): BigDecimal

    Permalink
    Definition Classes
    NumericOp
  5. implicit def BigIntToJBigInt(bi: BigInt): BigInteger

    Permalink
    Definition Classes
    NumericOp
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def operate(v1: Number, v2: Number): BigDecimal

    Permalink

    It is such a pain that there is no scala.math.Number base class above all the numeric types.

    It is such a pain that there is no scala.math.Number base class above all the numeric types.

    Definition Classes
    DivDecimalNumericOp
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  18. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from NumericOp

Inherited from AnyRef

Inherited from Any

Ungrouped