You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@daffodil.apache.org by "Costello, Roger L." <co...@mitre.org> on 2019/09/30 11:19:26 UTC
How are decimal (number with decimal point) values expressed in a
binary file?
Hello DFDL community,
Scenario: The book cost is: 19.95
The book data is in binary.
How is 19.95 expressed in binary?
How would the cost be expressed in a DFDL schema? Simply this:
<xs:element name="cost" type="decimal" />
/Roger
Re: How are decimal (number with decimal point) values expressed in a
binary file?
Posted by Steve Lawrence <sl...@apache.org>.
If the type were xs:float or xs:double, then the dfdl:binaryFloatRep
property defines how binary is converted to a number. Daffodil currently
only supports "ieee", which is IEEE 754-1985 floating point
representation. And byte lengths must be 4 for xs:float or 8 for xs:double.
Things are a bit different for xs:decimal. In that case, we parse the
number of bits as an integer (based on the dfdl:binaryNumberRep
property), and then move the decimal point of that integer base on the
value of dfdl:binaryDecimalVirtualPoint.
So in your example, let's say your field length was 2 bytes and
dfdl:binaryNumberRep="binary" (i.e. two's complement). In order to get a
value of 19.95, your data would contain the bytes 0x07CB (1995 in two's
complement binary) and you'd have dfdl:binaryDecimalVirtualPoint="2" to
move the decimal point two places to the left.
On 9/30/19 7:19 AM, Costello, Roger L. wrote:
> Hello DFDL community,
>
> Scenario: The book cost is: 19.95
>
> The book data is in binary.
>
> How is 19.95 expressed in binary?
>
> How would the cost be expressed in a DFDL schema? Simply this:
>
> <xs:element name="cost" type="decimal" />
>
> /Roger
>