Author |
Message
|
wmqstankela |
Posted: Mon Apr 15, 2019 5:01 am Post subject: JSON decimal precision problem |
|
|
Voyager
Joined: 29 Feb 2016 Posts: 94
|
Hi all.
I have a problem with setting decimal value in JSON tree. When i set this value to 4.12 iib sets it like I watnt, with two decimal places. But problem is when i cast value without decimal places
Code: |
SET OutputRoot.JSON.Data.Result = CAST('4' AS DECIMAL FORMAT '#0.00'); |
How to force broker to set this value with 2 decimal places, like 4.00?
Can anyone help me with this? |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 15, 2019 5:11 am Post subject: Re: JSON decimal precision problem |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
wmqstankela wrote: |
How to force broker to set this value with 2 decimal places, like 4.00? |
Tell broker you want a character value not a decimal.
A decimal value such as '4' has 7 decimal places if I remember the precision correctly. Any language will hold '4' as a decimal value and imply the lack of decimal places. Saying it's '4.12' will cause it to hold the extra decimal places. Try '4.12345' and see what happens.
'4.00' is a character string, hence the use of the character formatting string '#0.00' in your code. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
wmqstankela |
Posted: Mon Apr 15, 2019 5:26 am Post subject: |
|
|
Voyager
Joined: 29 Feb 2016 Posts: 94
|
Thanks Vitor for your answer.
I've got this '4.00' value like char from backend system, but I need to expose it like decimal with 2 decimal places.
Is there another way to keep this .00 value beside expose it like character? |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 15, 2019 5:47 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
wmqstankela wrote: |
Is there another way to keep this .00 value beside expose it like character? |
No. Because to a JSON parser
is the same value as
The JSON datatype is "number" and doesn't distinguish between integers, decimals and other floats the way other languages do.
wmqstankela wrote: |
I've got this '4.00' value like char from backend system, but I need to expose it like decimal with 2 decimal places. |
This is the key question: why do you need the extra zero decimal places?
Also if the backend system claims "4.00" is "like char", that's a clue. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
wmqstankela |
Posted: Mon Apr 15, 2019 5:56 am Post subject: |
|
|
Voyager
Joined: 29 Feb 2016 Posts: 94
|
I understand. It's clear to me now.
I need this to expose like 4.00 because client asking me for doing this.
Thanks Vitor, I need to explain them that this is not possible  |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 15, 2019 6:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
wmqstankela wrote: |
I need this to expose like 4.00 because client asking me for doing this. |
Are they asking for the value to be limited to 2 decimal places (which is reasonable but has clearly been badly explained to you as "we always want 2 decimal places) or are they just a bit dim (management)?
Obviously you have the option of passing this as a char "4.00" they can cast as a decimal on their end. If they're bound and determined to be dim (senior management). _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
rekarm01 |
Posted: Mon Apr 15, 2019 4:58 pm Post subject: Re: JSON decimal precision problem |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
wmqstankela wrote: |
But problem is when i cast value without decimal places
Code: |
SET OutputRoot.JSON.Data.Result = CAST('4' AS DECIMAL FORMAT '#0.00'); |
|
The FORMAT parameter describes the CHARACTER string, not the DECIMAL number. ESQL DECIMAL numbers can have a scale, and a precision, but they don't have a format.
Vitor wrote: |
The JSON datatype is "number" and doesn't distinguish between integers, decimals and other floats |
... and the IIB JSON parser does not support user-specified output formats for JSON numbers.
wmqstankela wrote: |
Is there another way to keep this .00 value beside expose it like character? |
There is always another way, (whether good, bad, or ugly). For example, the message flow could convert the output message to BLOB, and manually tweak it. |
|
Back to top |
|
 |
|