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 Index » WebSphere Message Broker (ACE) Support » Casting problem

Post new topic  Reply to topic Goto page 1, 2  Next
 Casting problem « View previous topic :: View next topic » 
Author Message
tanishka
PostPosted: Mon Oct 18, 2010 7:34 am    Post subject: Casting problem Reply with quote

Centurion

Joined: 24 Nov 2008
Posts: 144

Hi,

I am trying to cast from char to decimal pattern 0.00. But i am unable to get the pattern.

DECLARE ODESC DECIMAL;
DECLARE PATT CHAR '##0.00';
SET ODESC = CAST('1' AS DECIMAL FORMAT PATT DEFAULT 0.00);

Please help me?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon Oct 18, 2010 9:39 am    Post subject: Re: Casting problem Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

tanishka wrote:
Hi,

I am trying to cast from char to decimal pattern 0.00. But i am unable to get the pattern.

DECLARE ODESC DECIMAL;
DECLARE PATT CHAR '##0.00';
SET ODESC = CAST('1' AS DECIMAL FORMAT PATT DEFAULT 0.00);

Please help me?

Your pattern does not match the text. Try "1.00" as char...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
nukalas2010
PostPosted: Tue Oct 19, 2010 12:50 am    Post subject: Reply with quote

Master

Joined: 04 Oct 2010
Posts: 220
Location: Somewhere in the World....

Try like this...

DECLARE src CHARACTER '256478';
DECLARE tgt DECIMAL;
DECLARE model DECIMAL #0.00;
SET tgt= CAST(src AS DECIMAL FORMAT model);

I dnt know but I hope it works
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Oct 19, 2010 4:15 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

nukalas2010 wrote:
I dnt know but I hope it works


a) You could have tried it before posting it
b) I think that's a faint hope
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
tanishka
PostPosted: Wed Oct 20, 2010 9:37 am    Post subject: Reply with quote

Centurion

Joined: 24 Nov 2008
Posts: 144

DECLARE src CHARACTER '256478';
DECLARE tgt DECIMAL;
DECLARE model DECIMAL #0.00;
SET tgt= CAST(src AS DECIMAL FORMAT model);

Thank you nukalas2010. that worked fine.
Back to top
View user's profile Send private message
nukalas2010
PostPosted: Wed Oct 20, 2010 7:22 pm    Post subject: Reply with quote

Master

Joined: 04 Oct 2010
Posts: 220
Location: Somewhere in the World....

Back to top
View user's profile Send private message
KIT_INC
PostPosted: Thu Nov 04, 2010 10:02 am    Post subject: Reply with quote

Knight

Joined: 25 Aug 2006
Posts: 589

I have the same requirement to make a single digit (x) into 0.0x
I cannot even build the bar with your esql. I have a red x at
DECLARE model DECIMAL #0.00;

I tried
DECLARE CC CHAR;
DECLARE EE INT 5 ;
SET CC =CAST(EE AS CHAR FORMAT '##0.00');
I GOT CC = 5.00

if
DECLARE CC CHAR;
DECLARE EE CHAR '005' ;
SET CC =CAST(EE AS CHAR FORMAT '##0.00');
I GOT CC = 5

But what I want is 0.05

Any help?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Nov 04, 2010 7:01 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

KIT_INC wrote:
I have the same requirement to make a single digit (x) into 0.0x
I cannot even build the bar with your esql. I have a red x at
DECLARE model DECIMAL #0.00;

I tried
DECLARE CC CHAR;
DECLARE EE INT 5 ;
SET CC =CAST(EE AS CHAR FORMAT '##0.00');
I GOT CC = 5.00

if
DECLARE CC CHAR;
DECLARE EE CHAR '005' ;
SET CC =CAST(EE AS CHAR FORMAT '##0.00');
I GOT CC = 5

But what I want is 0.05

Any help?


So easy you didn't catch it. 0.05 is not an integer!.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
KIT_INC
PostPosted: Fri Nov 05, 2010 6:12 am    Post subject: Reply with quote

Knight

Joined: 25 Aug 2006
Posts: 589

Please excuse my ignorance, I still didn't get it. I know that 0.05 is not integer. I am declaring CC as char and I like it to be 0.05.
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Nov 05, 2010 6:37 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

KIT_INC wrote:
Please excuse my ignorance, I still didn't get it. I know that 0.05 is not integer. I am declaring CC as char and I like it to be 0.05.


So, thinking about your code and reviewing it, how do you see the value of EE (an integer of 5) being represented as 0.05 (not an integer)? Formatting aside, the value you're casting is 5 not 0.05. All the formatting is doing is changing how it's represented in character format. It's not changing the value.

So you tell me how you can hold a value of 0.05 in an integer & I'll tell you how to format it.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
KIT_INC
PostPosted: Fri Nov 05, 2010 8:31 am    Post subject: Reply with quote

Knight

Joined: 25 Aug 2006
Posts: 589

Thanks Vitor, I know that I cannot have 0.05 as Integer. I was thinking that the cast with format will help me to make my 5 into 0.05.
I was doing set CC= '0.0'||'5' before until I saw tanishka said that nukalas2010's code works. I am just learning to do things smarter.
But I was not able to get nukalas2010's code deployed. So I add my reply (or question) to this forum
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Nov 05, 2010 8:53 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

KIT_INC wrote:
I saw tanishka said that nukalas2010's code works.


I did wonder about that at the time.

One method I've seen used is:

Code:

DECLARE CC CHAR;
DECLARE EE INT 5 ;
SET CC =CAST((EE/100.00) AS CHAR FORMAT '##0.00');


Other solutions are undoubtably possible.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
nukalas2010
PostPosted: Mon Nov 08, 2010 4:19 am    Post subject: Reply with quote

Master

Joined: 04 Oct 2010
Posts: 220
Location: Somewhere in the World....

HI KIT,

Try this..
DECLARE src INTEGER 5;
DECLARE tgt DECIMAL;
DECLARE model CHARACTER '0.00';
SET tgt = CAST(src AS DECIMAL FORMAT model);

I came to know that you are trying to cast frm Integer to Decimal...
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Nov 08, 2010 5:21 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

nukalas2010 wrote:
I came to know that you are trying to cast frm Integer to Decimal...


How did you come to know that?

Also how does this code produce '0.05' rather than '5.00'?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
nukalas2010
PostPosted: Mon Nov 08, 2010 8:11 pm    Post subject: Reply with quote

Master

Joined: 04 Oct 2010
Posts: 220
Location: Somewhere in the World....

Vitor wrote:

Also how does this code produce '0.05' rather than '5.00'?


Oops.. Yeah with u Vitor..


DECLARE src INTEGER 5;
DECLARE tgt DECIMAL;
DECLARE model CHARACTER '0.00';
SET tgt = CAST((src/100.00) AS DECIMAL FORMAT model);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Casting 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.