Author |
Message
|
vishnurajnr |
Posted: Thu Mar 20, 2014 10:51 pm Post subject: Decimal formatting in DFDL |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
Hi,
I have a DFDL model (Simple one) which contains an element of 'Decimal' Type.
Its been observing that if the decimal value coming is like xx.00 (eg: 11.00) its taking as xx only and the decimal part is omitting (11.00 is coming as 11 only).
But if it is of xx.yy (eg: 11.23) its appearing correctly.
I want to parse the xx.00 as xx.00 itself and when serializing, if it is just xx, i would like to serialize as xx.00.
Would like to see if any options available. (I am using the decimal pattern as '#0.##')
Runtime version is 9.0.0.1 |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Mar 21, 2014 5:07 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
DFDL model constraints only apply when parsing data into the logical message tree and when serializing data from the logical message tree.
This is fundamental to using Message Broker.
So, be very clear.
Is your issue that the DFDL model is not creating the right format AFTER serialization?
Or is your issue that when you look at a logical value in the message tree, it's a logical value that has no bearing on any physical format? |
|
Back to top |
|
 |
vishnurajnr |
Posted: Fri Mar 21, 2014 6:09 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
mqjeff wrote: |
Is your issue that the DFDL model is not creating the right format AFTER serialization?
Or is your issue that when you look at a logical value in the message tree, it's a logical value that has no bearing on any physical format? |
My issue is:
I have an input field containing a value as 11.00, in DFDL this element is a decimal type. When parsing its appearing as 11, and not as 11.00.
But if the input is 11.01 or anything other than 11.00,its parsing as is.
So by default, DFDL will take the absolute value of a decimal if decimal point is 0? |
|
Back to top |
|
 |
Vitor |
Posted: Fri Mar 21, 2014 6:24 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
vishnurajnr wrote: |
My issue is:
I have an input field containing a value as 11.00, in DFDL this element is a decimal type. When parsing its appearing as 11, and not as 11.00. |
That I think is the point my most worthy associate is making. For a decimal data type, the 2 values 11 and 11.00 are equal.
So you don't really have an issue. You only think you do.
Unless you can explain why.
The only time 11 does not equal 11.00 is if you're outputing (not parsing) a decimal and you need it displayed to 2 decimal places. You specifically said "parsing", i.e. the insertion of a value into the data tree inside broker. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
vishnurajnr |
Posted: Fri Mar 21, 2014 6:36 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
Vitor wrote: |
So you don't really have an issue. You only think you do. |
I agree Vitor. But just curious to know if can parse the decimal type as it is.
Also will be helpful in case need to serialize the tree and display decimal with decimal points rather than showing as integer value. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Mar 21, 2014 6:56 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
vishnurajnr wrote: |
I agree Vitor. But just curious to know if can parse the decimal type as it is. |
As what is? You've already shown that you can successfully parse 11.00, 11.01, etc as their correct values so what other "type as it is" do you mean?
vishnurajnr wrote: |
Also will be helpful in case need to serialize the tree and display decimal with decimal points rather than showing as integer value. |
Why? If you're looking at the parsed value what's the difference between 11 & 11.00? If as a developer you're looking at the debugger and you see 11 rather than 11.00 what additional value do you get from a display of 11.00?
If you wish to display the decimal somewhere to an end user or similar then I already discussed that. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
vishnurajnr |
Posted: Fri Mar 21, 2014 7:21 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
Vitor wrote: |
If you wish to display the decimal somewhere to an end user or similar then I already discussed that. |
.
Unfortunately I am unable to find an answer from your replies in this post . I hope Kimbert could have replied.
I believe its clear in this post what I was asking
Can we display 11.00 as 11.00 if using a decimal type in DFDL? (Consider the serializing scenario).
See the below sample code as reference:
Code: |
CREATE LASTCHILD OF OutputRoot DOMAIN 'DFDL' NAME 'DFDL';
SET OutputRoot.Properties.MessageType= '{}:testinput';
SET OutputRoot.DFDL.testinput.Input.in1 = 11.00;
SET OutputRoot.DFDL.testinput.Input.in2 = 11.01;
SET OutputRoot.DFDL.testinput.Input.in3 = 11.10; |
My DFDL:
Code: |
<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:ibmDfdlExtn="http://www.ibm.com/dfdl/extensions" xmlns:ibmSchExtn="http://www.ibm.com/schema/extensions" xmlns:recSepFieldsFmt="http://www.ibm.com/dfdl/RecordSeparatedFieldFormat" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.ibm.com/dfdl/RecordSeparatedFieldFormat" schemaLocation="IBMdefined/RecordSeparatedFieldFormat.xsd"/>
<xsd:element ibmSchExtn:docRoot="true" name="testinput">
<xsd:complexType>
<xsd:sequence dfdl:separator="%CR;%LF;">
<xsd:element dfdl:occursCountKind="implicit" maxOccurs="unbounded" name="Input" type="Msg"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="Msg">
<xsd:sequence>
<xsd:element dfdl:textNumberPattern="#0.###" name="in1" type="xsd:decimal"/>
<xsd:element dfdl:textNumberPattern="#0.###" name="in2" type="xsd:decimal"/>
<xsd:element dfdl:textNumberPattern="#0.###" name="in3" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
<xsd:annotation>
<xsd:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format byteOrder="{$dfdl:byteOrder}" encoding="US-ASCII" escapeSchemeRef="recSepFieldsFmt:RecordEscapeScheme" occursCountKind="fixed" ref="recSepFieldsFmt:RecordSeparatedFieldsFormat"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:schema> |
.
This will produce an output as:
What if I need an output like
? |
|
Back to top |
|
 |
Vitor |
Posted: Fri Mar 21, 2014 7:39 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
vishnurajnr wrote: |
What if I need an output like
? |
Ok, that's not parsing. That's what I called above "displaying". And what you're doing is not that. You're outputting it as a decimal so in DFDL terms it's happy that 11 = 11.00.
If you want to display it as 11.00 then that's a specific character format. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Mar 21, 2014 7:55 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Hi,
Why have you chosen this setting:
Code: |
dfdl:textNumberPattern="#0.###" |
Have you experimented with other settings? _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
vishnurajnr |
Posted: Fri Mar 21, 2014 7:55 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
Finally I found the solution.
We can play with the numberpatern property in DFDL editor (under 'Text Content' properties and apply the pattern)
I found the pattern as '#0.00 instead of ''#0.##' will serialize the decimal portion.
eg:
Code: |
<xsd:element dfdl:decimalSigned="yes" dfdl:textNumberCheckPolicy="strict" [b]dfdl:textNumberPattern="#0.00" [/b]dfdl:textNumberRep="standard" ibmDfdlExtn:sampleValue="1.0" name="in1" type="xsd:decimal"/> |
Thanks for all your suggestions..  |
|
Back to top |
|
 |
kimbert |
Posted: Fri Mar 21, 2014 7:56 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Just too late. Glad you found the answer. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
|