ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Leading zero using %editc

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

  • Leading zero using %editc

    In one of my programs I have a numeric field that I need to express as a character string with one leading zero before the decimal point. Example, I need to display .12345 as 0.12345.

    The value if the field is always < 1 so there will always be a 0 before the decimal point

    actually I meant %editw not %editc. Can't change the title now

  • #2
    Re: Leading zero using %editc

    use %editc "X"
    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: Leading zero using %editc

      It isn't perfect but this is my example using %editw:

      Code:
           DnumVal           s              6  5 inz(.12345)
           DcharVal          s             10a
            /free
      
             charVal = %editw(numVal: '0 .     ');
             *inlr = *on;
      
            /end-free
      I have a few extra spaces but if you debug it you get CHARVAL = ' 0.12345 '. You can play around with it and get it to work for your environment. The trick is not to put the 0 right before the decimal because the 0 is kind of like saying stop zero surpressing here. So if you put it two spaces in front of the decimal, you get the results you requested. Again, my example isn't perfect but you get the idea.
      Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest. - Isaac Asimov

      Comment


      • #4
        Re: Leading zero using %editc

        %editc omits the decimal point.

        .12345 becomes 12345

        Comment


        • #5
          Re: Leading zero using %editc

          My bad didn't see the earlier post !!
          PHP Code:
          d number          s              7  4 inz(06.0201)              
          d char7           s              7                              
           
          *                                                              
           /
          free                                                          
                                                                          
                 
          // '6.0201  '                                            
                 
          char7 = %trim(%editw(number:'0  .    '));                
                                                                          
                *
          inlr = *on;                                              
           /
          end-free 
          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


          • #6
            Re: Leading zero using %editc

            Hi gregwga50:

            %editc omits the decimal point.
            %editc(mynum : 'X') omits the decimal point there are other edit codes.

            a list of edit codes can be found here:
            How to use the Edit Code %EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol}) This function returns a character result repr...


            Best of Luck
            GLS
            The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

            Comment

            Working...
            X