ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%Dec function!!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • %Dec function!!!

    Dtot S 4p 2
    Dval s 6a
    C eval val= '564452'
    C eval tot = %dec(val:4:2)
    C DSPLY tot
    C RETURN

    compiling it it is givin me :

    The target for a numeric operation is too small to hold the result (C G D F)

    wut u think i should adjust?
    am following this expression :
    %DEC(numeric or character expression{recision:decimal places}) isn't it right?

  • #2
    Re: %Dec function!!!

    Since you do not are have a decimal point in â??valâ?? like 5644.52 the â??%decâ?? takes for granted that the value are 6 long. To make sure that the %dec function can hold it all you must add the number of decimals to it or divide with 100 after.

    Remember to make the tot longer like 9p2.

    This sample here works fine

    Code:
    Dtot              s              9p 2             
    Dval              s              6                
    C                   eval      val= '564452'       
    C                   eval      tot = %dec(val:6:0) 
    C                   eval      tot = tot / 100     
    C                   RETURN

    Bent

    Comment


    • #3
      Re: %Dec function!!!

      i did wut u said but still getting same error : why??


      Dtot S 9p 2
      Dval S 6A inz('564478')
      C EVAL tot = %dec(val: 6: 2)
      C DSPLY tot
      C RETURN

      Comment


      • #4
        Re: %Dec function!!!

        This time, you are trying to extract 2 chars from the 6th char onwards. But there are only 6 chars in the source.
        â??No bird soars too high if he soars with his own wingsâ?? â?? William Blake

        Comment


        • #5
          Re: %Dec function!!!

          Dtot S 9p 2
          Dval S 6A inz('564478')
          C EVAL tot = %dec(val: 6: 2)
          C DSPLY tot
          C RETURN

          No. The %dec parms are field length, decimals. So the highest number that can result from the command is 9999.99. You are trying to process 564,478. To handle this big a number, you would need to use %dec(val:8:2) to get a result of 564478.00 (8 length, 2 dec). If you are going to make tot a 9P 2 field, you probably want %dec(val:9:2)

          Comment


          • #6
            Re: %Dec function!!!

            Oops! I mistook it for a substring.
            â??No bird soars too high if he soars with his own wingsâ?? â?? William Blake

            Comment


            • #7
              Re: %Dec function!!!

              Hi,

              because there is no decimal point (or comma) in the character string, you first have to convert the string into a numeric value with zero decimal points and divide after through 100.

              Example:
              PHP Code:
               /Free
                 Monitor
              ;
                    
              NumValue = %Int(CharValue) / 100;
                 
              On-Error;
                    
              //Error Do something
                 
              EndMon;
               /
              EndFree 
              Birgitta

              Comment

              Working...
              X