ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

is there an easier way..my brain hurts

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

  • is there an easier way..my brain hurts

    PHP Code:
    ~
    d howmanyitems    s              4  0 inz(5)         
    d howmanylabels   s              4  0                
                                                         
                                                         
     
    /free                                               
                                                         
      howmanylabels 
    howmanyitems/4;                    
      if %
    rem(howmanyitems:4) > *zeros;                  
       
    howmanylabels +=1;                                
      endif;                                             
      *
    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

  • #2
    Re: is there an easier way..my brain hurts

    Originally posted by jamief View Post
    PHP Code:
    ~
    d howmanyitems    s              4  0 inz(5)         
    d howmanylabels   s              4  0                
                                                         
                                                         
     
    /free                                               
                                                         
      howmanylabels 
    howmanyitems/4;                    
      if %
    rem(howmanyitems:4) > *zeros;                  
       
    howmanylabels +=1;                                
      endif;                                             
      *
    inlr = *on;                                       
                                                         
     /
    end-free 
    Would this do it ?

    howmanylabels = (howmanyitems/4 + .999);

    Comment


    • #3
      Re: is there an easier way..my brain hurts

      I don't think that last one works (I might be wrong though). Are we always trying to round up? If that's the case then I think the first solution was more explicit.

      This is the way I think I would try and do it...
      PHP Code:
      // Adding just a whisker under a half means we always round up
      howmanylabels = %IntH((howmanyitems/4)+0.4999); 
      Ben

      Comment


      • #4
        Re: is there an easier way..my brain hurts

        Thanks guys .... Yes I must round up if there is any remainder at all.

        jamie "fridays Rock!" flanary
        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


        • #5
          Re: is there an easier way..my brain hurts

          Hi,

          yet an other solution:

          PHP Code:
             Exec SQL  :HowManyLabels Ceiling(:HowManyItems 4.0); 
          Birgitta

          Comment


          • #6
            Re: is there an easier way..my brain hurts

            Birgitta,

            Thanks once again.......Your SQL skills are second to none!

            jamie
            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


            • #7
              Re: is there an easier way..my brain hurts

              Jamie,

              thanks, that turns me always red.

              Birgitta

              Comment


              • #8
                Re: is there an easier way..my brain hurts

                This is my new thing to learn for today

                The CEIL or CEILING function returns the "smallest integer value that is greater than or equal to expression".

                The FLOOR function returns the largest "integer value less than or equal to expression".

                V5R3 SQL references can be seen here

                Thanks Birgitta !

                GC
                Greg Craill: "Life's hard - Get a helmet !!"

                Comment


                • #9
                  Re: is there an easier way..my brain hurts

                  Birgitta Rocks!

                  Comment

                  Working...
                  X