You can use the fn:round-half-to-even function. The first argument is
the number to round and the second is the precision to round to. For
example:

  fn:round-half-to-even(77.74999591708135, 2)

will return 77.75

On 9/4/19 1:46 PM, Costello, Roger L. wrote:
> Thanks Mike. Now it works. But look at the XML output, below. Way too many 
> digits to the right of the decimal point. Ordinarily I would use the XPath 
> format-number() function to remove some of those digits, but Daffodil doesn’t 
> support format-number(). Is there something else that I can use?
> 
> /Roger
> 
> <input>
> <command-code>4</command-code>
> <longitude>
> <raw>3623412</raw>
> <degrees>77.74999591708135 degrees east</degrees>
> </longitude>
> <area-code>3</area-code>
> </input>
> 
> *From:* Beckerle, Mike <mbecke...@tresys.com>
> *Sent:* Wednesday, September 4, 2019 1:27 PM
> *To:* users@daffodil.apache.org
> *Subject:* [EXT] Re: Non-terminating decimal expansion ... huh?
> 
> You are doing divisions among integers.
> 
> If you want it to convert to floating point you need to be explicit.
> 
> Otherwise it tries to keep things as decimal, but clearly that can't work for 
> division.
> 
> I suggest changing your 180 constants to xs:double(180) That should force 
> everything to convert into double-precision floating point.
> 
> --------------------------------------------------------------------------------
> 
> *From:*Costello, Roger L. <coste...@mitre.org <mailto:coste...@mitre.org>>
> *Sent:* Wednesday, September 4, 2019 1:18 PM
> *To:* users@daffodil.apache.org <mailto:users@daffodil.apache.org> 
> <users@daffodil.apache.org <mailto:users@daffodil.apache.org>>
> *Subject:* Non-terminating decimal expansion ... huh?
> 
> Hello DFDL community,
> 
> The below DFDL schema produces this error message:
> 
> *[error] Parse Error: Non-terminating decimal expansion; no exact 
> representable 
> decimal result. (within Expression Evaluation Error: Non-terminating decimal 
> expansion; no exact representable decimal result.*
> 
> What does that mean? Why am I getting it? How to fix it?  /Roger
> 
> <xs:elementname="input">
> <xs:complexType>
> <xs:sequence>
> <xs:elementname="command-code"type="unsignedint3"/>
> <xs:elementname="longitude">
> <xs:complexType>
> <xs:sequence>
> <xs:elementname="raw"type="unsignedint24"/>
> <xs:elementname="degrees"type="xs:string"dfdl:inputValueCalc="{
>                              if (../raw eq 0) then '0 degrees'
>                              else if (../raw lt 8388607) then 
> fn:concat((../raw 
> * 180 div 8388607), ' degrees east')
>                              else fn:concat('-',((../raw - 8388607) * 180 div 
> 8388607), ' degrees west')
>                              }"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:elementname="area-code"type="unsignedint5"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> 

Reply via email to