Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

%dec

Status
Not open for further replies.

cat5ive

MIS
Dec 3, 2004
184
US
What's wrong with this? I got error msg 'The target for a numeric operation is too small to hold the result'.

D text s 9 inz('12345')
D newnum s 15 3

newnum = %dec(text:6:3);


Thanks in advance
 
It's been awhile since I've worked with packed precision numbers but I'll give it a try. Try increasing the value of newnum to 18 3. Precision 6 and decimal 3 when unpacked will have a result of 18 including check digits. Or try converting text into a pack decimal. You can also decrease the precision. Hope this helps.
 
Hi,

I increased newnum to 20 3, still get the same error msg.
I want to convert text string to decimal field. What's the
other BIF beside %dec?

Thanks

 
Hi,

I got it. It's the length of the 'TEXT' that I need to
increase.


 
Hi,

Actually it still not working. Still need help please.

Thanks
 
Code:
D Text            s              9a   inz('12345')
D NewNum          s             15  3             
D Length          C                   const(12)   
D DecPos          C                   const(3)    
                                                  
 /Free                                            
        NewNum = %Dec( Text: Length: DecPos ) ;   
        ...

You get NewNum = 12345.000

Remember that the 2nd argument of the %DEC BIF is the number of digits in the resulting numeric value, not the length of the character string and the 3rd argument the number of decimal places in the same resulting numeric value.

 
Correct. Its not the size of newnum that was the problem - it was the %dec(text:6:3) What this says is you want a 6 position numeric with 3 decimals (xxx.xxx). This allows only 3 positions to the left of the decimal. If you use
%dec(text:15:3) you would be OK.
 
Thanks, guys. it works. My next question is, how do I get
the decimal to show up.
Code:
D text            s           7    inz(' 123.45')         
D newnum          s          15p 2                        
D length          c                const(15)              
D pos             c                const(2)               
  
                                                         
     newnum = %dec(text:length:pos);
My newnum show 12345 not 123.45. I tried to inz text with
(' 12345'). It did not work either.

Thanks
 
Your code is correct, it does work !

Code:
D Text            s              7a   inz(' 123.45')     
D NewNum          s             15p 2                    
D Length          C                   const(%Len(Text))  
D DecPos          C                   const(2)           
                                                         
 /Free                                                   
        NewNum  = %Dec( Text: Length: DecPos ) ; 
        Dump(a) ;
        *Inlr= '1' ;        
 /End-Free

Here is what the dump shows :

Code:
 NAME                  ATTRIBUTES           VALUE                               
 NEWNUM                PACKED(15,2)         [b][COLOR=red]0000000000123.45[/color][/b]                    
                       VALUE IN HEX         '000000000012345F'X                 
 TEXT                  CHAR(7)              ' 123.45'        '40F1F2F34BF4F5'X
 
Got it now. It was because I did 'DSPLY newnum'. That's why
it did not show decimal.

Thanks again everyone.
 
Only problem with this TalkTurkey, is that is the text value is something like 1234567, your code will fail. Using
D Length C const(%Len(Text))

Will leave the field short. The length should be at least the length of text + the number of decimals to handle the largest values in text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top