Announcement

Collapse
No announcement yet.

CINT rounding

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

  • CINT rounding

    From the PBWin 9.0 help on the CINT-CWRD group:
    In the case of the functions that convert to integer-class values, the fractional part of the number is rounded to the nearest even number. For example, CINT(1.5) returns 2, CINT(.5) returns 2, and CLNG(-0.6) returns -1.
    It seems that the last two examples are not in sync with the statement. It seems pretty obvious to me but I thought I'd post just in case I've had my head buried in numbers too long to understand words before sending it in to support.
    I would think that if the numbers are being rounded to the nearest even integer that the last two examples would return 0, for those of us that consider 0 an even integer.

    After testing, CINT(0.5) returns 0, CINT(-0.6) returns -1, CINT(0.6) returns 1.
    Last edited by Rodney Hicks; 18 Oct 2008, 07:59 AM. Reason: test results
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

  • #2
    You're not hallucinating or anything. It definitely could use a support rewrite. The tricky part is with the ".5" instance: eg. 1.5 rounds up to 2 because odd (referring to the 1st number left of the decimal pt.) rounds up, and 2.5 rounds down to 2 because even rounds down in what's called unbiased or bankers rounding.
    Last edited by John Gleason; 18 Oct 2008, 08:40 AM. Reason: the 1st number

    Comment


    • #3
      This statement from the PBWin 8 manual is as follows:
      "In the case of the functions that convert to integer-class values, the result is rounded up if it has a fractional component of 0.5 or greater. For example, CINT(0.7) returns 1 and CLNG(-0.6) returns -1."

      This is different than the bankers rounding in PBWin 9.00.
      Rod
      In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

      Comment


      • #4
        See also: CEIL() and FIX() functions. (especially if dealing with signed numbers)
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Good catch on those PB8 docs too Rod. The function works the same in 8 and 9--both use banker's rounding--but the docs need correction in both. My docs in ver. 8 say For example, CINT(1.5) returns 1 which isn't correct.

          Comment


          • #6
            And in PBCC 4 the help file states:
            In the case of the functions that convert to integer-class values, the result is rounded down if it has a fractional component of 0.5 or less. For example, CINT(1.5) returns 1, and CLNG(-0.6) returns -1.
            And the manual says "rounded up if it has a fractional component of 0.5 or greater.

            I don't have PBCC 5 yet so I can't check that, so I'll leave that to someone that does have it.

            Not a much used function so it probably escaped notice.
            Last edited by Rodney Hicks; 18 Oct 2008, 09:39 AM.
            Rod
            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

            Comment

            Working...
            X