Author |
Message
|
Muthukrishnan |
Posted: Tue Jun 18, 2013 11:01 pm Post subject: Retrieving decimal values in message broker |
|
|
Apprentice
Joined: 16 Feb 2013 Posts: 48
|
Hi,
Below is my requirement. Can anyone please help to get the output for all the possible combinations of the input below.
Code: |
Input - 22.50
Output-22.5
Input - 50.00
Output - 50
Input - 77.70
Output - 77.7
Input - 16.50
Output - 16.5
|
|
|
Back to top |
|
 |
kimbert |
Posted: Wed Jun 19, 2013 2:43 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
So the rules seem to be:
- For fractional numbers, write the value with one digit after the decimal point
- for integer numbers, write the value with no decimal point
Is that corrrect?
You need to tell us
a) the rounding rules are ( what output do you want for 22.54, 22.55 and 22.56? ).
b) what the output format is ( XML / DFDL etc ) |
|
Back to top |
|
 |
lancelotlinc |
Posted: Wed Jun 19, 2013 3:13 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
kimbert wrote: |
You need to tell us
a) the rounding rules are ( what output do you want for 22.54, 22.55 and 22.56? ).
b) what the output format is ( XML / DFDL etc ) |
Also would be helpful for the OP to tell us what s/he has tried, and what the results were. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
Muthukrishnan |
Posted: Wed Jun 19, 2013 4:19 am Post subject: |
|
|
Apprentice
Joined: 16 Feb 2013 Posts: 48
|
Quote: |
If the input is 22.55 then output also should be 22.55. Also the input and output are XML. I am trying couple of things. But not getting a concrete code to post as I am new to esql. |
|
|
Back to top |
|
 |
kimbert |
Posted: Wed Jun 19, 2013 4:52 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Ah! So the requirement is to remove trailing zeros without changing the value of the decimal. That makes it very easy.
1. Create or obtain an XSD that describes your input XML
2. Deploy the XSD along with the message flow. How you do that will depend on which version you are using, but it's all described in the info center.
3. On the input node, set Validation to 'Content and Value' and tick the box that says 'Build tree using XML Schema types'.
4. The message tree will now contain decimal values instead of strings. When the XMLNSC parser outputs the message tree as XML, there will be no trailing zeros.
Last edited by kimbert on Wed Jun 19, 2013 6:07 am; edited 1 time in total |
|
Back to top |
|
 |
vmcgloin |
Posted: Wed Jun 19, 2013 4:59 am Post subject: |
|
|
Knight
Joined: 04 Apr 2002 Posts: 560 Location: Scotland
|
Make use of the infocentre if you aren't already.
Maybe try cast with a format of 00.## or post exactly what you are trying and the results you get.
Edited to add: sorry - i did not see the previous response. I didn't mean to cause offence and I come from a land where fully message xsd's are rare  |
|
Back to top |
|
 |
Muthukrishnan |
Posted: Wed Jun 19, 2013 6:41 pm Post subject: Retrieving decimal values in message broker |
|
|
Apprentice
Joined: 16 Feb 2013 Posts: 48
|
Dear all,
Thanks for your suggestions. Let me try them. But I am afraid I wont be having xsd. I would like to handle them in esql. Is there any way to remove only the trailing zeros and not to disturb the decimals values if present in the input ? |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jun 19, 2013 8:53 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You can try and cast your numbers to a decimal type?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
AkankshA |
Posted: Wed Jun 19, 2013 10:30 pm Post subject: |
|
|
 Grand Master
Joined: 12 Jan 2006 Posts: 1494 Location: Singapore
|
the dirty method to do would be to take the number after the decimal, trim the '0' of the right side and then concat it back...
but like i said, its a dirty method and shall be your last option _________________ Cheers |
|
Back to top |
|
 |
kimbert |
Posted: Thu Jun 20, 2013 5:21 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Is there any way to remove only the trailing zeros and not to disturb the decimals values if present in the input ? |
Yes - use ESQL CAST to do what the XML parser would have done
- convert the string to a logical decimal value
- convert the decimal value back to a string
The CAST function is very well documented, so please excuse me if I leave the details up to you. |
|
Back to top |
|
 |
|