Uploaded image for project: 'Daffodil'
  1. Daffodil
  2. DAFFODIL-2043

fn:round-half-to-even returns decimal string

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.3.0
    • Front End
    • None

    Description

      fn:round-half-to-even() appears to be returning a decimal string, which causes issues when an integer type is expected.

      The following elements both trigger a schema definition error

      <xs:element name="a" type="xs:int"
      dfdl:inputValueCalc="{ (fn:round-half-to-even( 0.1 )) }"
      />

      <xs:element name="a" type="xs:int"
      dfdl:inputValueCalc="{ xs:int(fn:round-half-to-even( 0.1 )) }"
      />

      [error] Schema Definition Error: Cannot convert '0.0' from String type to Long (Cannot convert to type long: For input string: "0.0").

      In contrast, casting to a double, as below, appears to work as expected:

      <xs:element name="a" type="xs:int"
      dfdl:inputValueCalc="{ xs:double(fn:round-half-to-even( 0.1 )) }"
      />

       

      What appears to be happening is that fn:round-half-to-even( 0.1 ) returns the string "0.0", and the type="xs:int" on the element triggers an implicit cast to an integer type. Since "0.0" contains a decimal point, this cast fail. However, an explict cast to xs:double can succeed, and then the explicit cast to an int from the double works as expected.

      Complete example schema attached

      Attachments

        1. test.dfdl.xsd
          1 kB
          Brandon Sloane

        Activity

          People

            slawrence Steve Lawrence
            brandon.sloane Brandon Sloane
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: