ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Math calculation

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

  • Math calculation

    Ok,

    I have a field which I need to divide by 2, and the round up if the resultant figure is not a whole number.

    I can achieve this as follows..

    Code:
    c     length        div       2             result       
    c                   mvr                     remain       
    c                   if        remain > 0                 
    c                   add       1             result       
    c                   endif
    I was wondering if there is a BIF or another simpler way of doing the same calculation?

    Thanks in advance

  • #2
    Re: Math calculation

    result = length / 2
    if %rem(length:2) > 0
    result += 1
    Endif

    Comment


    • #3
      Re: Math calculation

      Hi,

      there is no BIF in RPG but a SQL scalar function CEILING or CEIL that can be used instead.
      The CEIL or CEILING function returns the smallest integer value that is greater than or equal to the value or result of a formular specified in the paranthesis.

      PHP Code:
      C/EXEC SQL  Set :MyResult CEILING(:MyLength/2)
      C/END-EXEC 
      Birgitta

      Comment


      • #4
        Re: Math calculation

        Have the result as zero decimal places and try this

        result = (number/2) + .9;

        Comment


        • #5
          Re: Math calculation

          Cool,

          so many different ways of getting what I wanted - thanks guys

          Comment


          • #6
            Re: Math calculation

            We aim to please! You aim too! Please!




            (Is this a great site or what??)

            Comment


            • #7
              Re: Math calculation

              *aims at FaStOnE*

              Comment


              • #8
                Re: Math calculation

                How did I know THAT was coming!


                (hahahahahaha)

                Comment


                • #9
                  Re: Math calculation

                  glad I didn't disappoint you

                  Comment

                  Working...
                  X