ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Decimal point

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

  • Decimal point

    hey all,
    my question concerns the decimal values

    in my RPG program how can i make a disaply field to be with decimal point
    example 1500.50

    Dtamnt S 15P 2
    Dtpamt S 32A

    Eval tamnt = 0
    eval tpamt = %subst(SRCDTA:11:15)
    eval tamnt = tamnt+%DEC(tpamt:15:2)
    dsply tamnt


    but the tamnt come with value 15005000 rather than wut i wanted 1500.50

    what should i do?

  • #2
    Re: Decimal point

    something like this

    eval tamnt = %editc(tamnt+%DEC(tpamt:15:2):'J')
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Decimal point

      Hi,

      try the following:
      PHP Code:
      /Free
         Dsply 
      (%Char(tamnt));
      /
      End-Free 
      Birgitta

      Comment


      • #4
        Re: Decimal point

        i didn't work jamief

        when i write this :

        C eval tpamt = %subst(SRCDTA:AMNT_ST:AMNT_LEN)
        C eval tamnt = tamnt+%DEC(tpamt:15:2)

        it means when i use 5DEC it put two digits after the decimal point or not?
        what is the 2 for?

        coz the tpamt is a character field

        Comment


        • #5
          Re: Decimal point

          Hi

          LP Zdenko

          Comment


          • #6
            Re: Decimal point

            Hello

            I had this problem a while ago with fields imported from XML (or SOAP from the web-service), that had the wrong number of decimal places. In our system we store many numeric values as character, so that we can keep them all in the same place, and I don't need to write a new XML parser every time.

            Anyway this is my little program I wrote. I thought it was quite cute:
            Code:
            DZeros            s            100A   Inz(*Zeros)                           
            DNumberC          s             20A                                         
            DDecimals         s              3  0                                       
            DPoint            s              3  0                                       
            DTempC            s             20A                                         
             *                                                                          
            D DecLen          PR            40A                                         
            D   NumberTemp                  40A   Value                                 
            D   Decs                         3  0 Value                                 
             *                                                                          
            C     *Entry        Plist                                                   
            C                   Parm                    NumberC                         
            C                   Parm                    Decimals                        
             *                                                                          
            C                   Eval      NumberC = %Trim(DecLen(NumberC:Decimals))     
             *                                                                          
            C                   Seton                                        LR         
             *                                                                          
            PDecLen           B                                                         
             *                                                                           
            DDecLen           PI            40A                                          
            D  NumberTemp                   40A   Value                                  
            D  Decs                          3  0 Value                                  
             *                                                                           
            C                   If        Decs > 0                                       
            C                   Eval      NumberC = %Trim(NumberC)                       
            C                   Eval      Point = %Scan('.':NumberC)                     
            C                   If        Point > 0                                      
            C                   Eval      TempC = %SubSt(NumberC : Point : Decs+1)       
            C                   Eval      TempC = %Trim(TempC) + %SubSt(Zeros:1:         
            C                                     (1 + Decimals - %Len(%Trim(TempC))))   
            C                   Eval      NumberC = %SubSt(NumberC:1:Point-1)            
            C                   Else                                                     
            C                   Eval      TempC = '.' + %SubSt(Zeros : 1 : Decs)         
            C                   Endif                                                    
            C                   Eval      NumberC = %Trim(NumberC) + %Trim(TempC)        
            C                   Endif                                                    
            C                   Return    NumberC                                        
             *                                                                           
            P                 E

            Comment


            • #7
              Re: Decimal point

              i saw this example but still didn't get the point what type include the decimal point to the field?

              Comment


              • #8
                Re: Decimal point

                what abt the EDTCDE it is used for what and how?

                Comment


                • #9
                  Re: Decimal point

                  If you have a char field with a deciaml numeric in it, you need only code one line

                  Number = %dec(Alphafield:15:2)
                  It will automatically align the decimal and ignore any blanks (before, after, embedded). Change the 15:2 as needed. To change it back to an alpha field and keep the decimal point, use the EDTCDE

                  AlphaField = %edtcde(Number:'J') Change the "J" as needed to get the desired look in the alpha field.

                  Comment


                  • #10
                    Re: Decimal point

                    hi
                    when i try to put the second syntax without the %
                    it gives me
                    Expression contains an operand that is not defined.

                    and when i use as u said the % ican't compilet it it gives error

                    Comment


                    • #11
                      Re: Decimal point

                      Hi,

                      the compiler is right. the BIF %EdtCde does not exist. You have to specify %EditC instead.

                      Birgitta

                      Comment

                      Working...
                      X