ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexWebSphere Message Broker SupportJSON decimal precision problem

Post new topicReply to topic
JSON decimal precision problem View previous topic :: View next topic
Author Message
wmqstankela
PostPosted: Mon Apr 15, 2019 5:01 am Post subject: JSON decimal precision problem Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Mon Apr 15, 2019 5:11 am Post subject: Re: JSON decimal precision problem Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25823
Location: Ohio, 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
View user's profile Send private message
wmqstankela
PostPosted: Mon Apr 15, 2019 5:26 am Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Mon Apr 15, 2019 5:47 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25823
Location: Ohio, USA

wmqstankela wrote:
Is there another way to keep this .00 value beside expose it like character?


No. Because to a JSON parser

Code:
{"something":4}


is the same value as

Code:
{"something":4.00}


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
View user's profile Send private message
wmqstankela
PostPosted: Mon Apr 15, 2019 5:56 am Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Mon Apr 15, 2019 6:32 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25823
Location: Ohio, 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
View user's profile Send private message
rekarm01
PostPosted: Mon Apr 15, 2019 4:58 pm Post subject: Re: JSON decimal precision problem Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1370

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
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexWebSphere Message Broker SupportJSON decimal precision problem
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.