Author |
Message
|
tanishka |
Posted: Mon Oct 18, 2010 7:34 am Post subject: Casting problem |
|
|
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 |
|
 |
fjb_saper |
Posted: Mon Oct 18, 2010 9:39 am Post subject: Re: Casting problem |
|
|
 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 |
|
 |
nukalas2010 |
Posted: Tue Oct 19, 2010 12:50 am Post subject: |
|
|
 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 |
|
 |
Vitor |
Posted: Tue Oct 19, 2010 4:15 am Post subject: |
|
|
 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 |
|
 |
tanishka |
Posted: Wed Oct 20, 2010 9:37 am Post subject: |
|
|
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 |
|
 |
nukalas2010 |
Posted: Wed Oct 20, 2010 7:22 pm Post subject: |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
|
Back to top |
|
 |
KIT_INC |
Posted: Thu Nov 04, 2010 10:02 am Post subject: |
|
|
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 |
|
 |
fjb_saper |
Posted: Thu Nov 04, 2010 7:01 pm Post subject: |
|
|
 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 |
|
 |
KIT_INC |
Posted: Fri Nov 05, 2010 6:12 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Fri Nov 05, 2010 6:37 am Post subject: |
|
|
 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 |
|
 |
KIT_INC |
Posted: Fri Nov 05, 2010 8:31 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Fri Nov 05, 2010 8:53 am Post subject: |
|
|
 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 |
|
 |
nukalas2010 |
Posted: Mon Nov 08, 2010 4:19 am Post subject: |
|
|
 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 |
|
 |
Vitor |
Posted: Mon Nov 08, 2010 5:21 am Post subject: |
|
|
 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 |
|
 |
nukalas2010 |
Posted: Mon Nov 08, 2010 8:11 pm Post subject: |
|
|
 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 |
|
 |
|