Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_Round () issue
#1
I know this is a 'nit -- a very minor thing, but it probably should be fixed in the future.

It is that _Round(5/10) should be 1, but it is 0.  And there is a pattern: 25, 45, 65, etc. 
But maybe that is an alternative rule that I don't know about.  It is a 'nit.

Code: (Select All)
[ deleted 5/13 - incorrect ]
Reply
#2
It's allot of people's nit!

Luke explained it as bankers rounding, so that not every 5 is rounded up but every other 5 is.
b = b + ...
Reply
#3
Round() function always round to lower value
Reply
#4
Easiest solution I've found for this type of thing -- just write your own Round function:

Code: (Select All)
Print _Pi
For i = 14 To 0 Step -1
    Print Round(_Pi, i)
Next

Function Round## (num As _Float, toDecPlace As _Unsigned _Byte)
    Round = Int(num * 10 ^ toDecPlace + .5) / 10 ^ toDecPlace
End Function

Can easily round to whatever decimal point you want with the above. Smile
Reply
#5
From the wiki:

The _ROUND function rounds to the closest even INTEGER, LONG or _INTEGER64 numerical value.

It may be a bit confusing wording, as _ROUND does not always choose the even result, it only does so when starting from .5
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply
#6
Exclamation [ meaning: "got it"; "thanks"; "am processing"; "reserve the right to continue later" ]
Reply
#7
> bplus: "Luke explained it as bankers rounding, so that not every 5 is rounded up but every other 5 is."

Yes, it is (now) clear that _ROUND rounds n.5 up if n is odd and down if n is even.
Int(n.5) always rounds n.5 up. [ Edit: WRONG ! ] SMcNeill's Round##(n.5,0) also always rounds up.

> aural: "Round() function always round to lower value"

Wha--?
Reply
#8
(05-13-2022, 12:45 AM)dcromley Wrote: > bplus: "Luke explained it as bankers rounding, so that not every 5 is rounded up but every other 5 is."
 
  Yes, it is (now) clear that _ROUND rounds n.5 up if n is odd and down if n is even.
  Int(n.5) always rounds n.5 up.  SMcNeill's Round##(n.5,0) also always rounds up.

> aural: "Round() function always round to lower value"

  Wha--?

I'm sure just a mis-word but INT() always rounds down for positives anyway. 

BTW that's another crazy issue to worry about, rounding with negatives. I'm not sure you always want to add .5 in SMcNeill's Round##()
b = b + ...
Reply
#9
(05-13-2022, 01:08 AM)bplus Wrote:
(05-13-2022, 12:45 AM)dcromley Wrote: > bplus: "Luke explained it as bankers rounding, so that not every 5 is rounded up but every other 5 is."
 
  Yes, it is (now) clear that _ROUND rounds n.5 up if n is odd and down if n is even.
  Int(n.5) always rounds n.5 up.  SMcNeill's Round##(n.5,0) also always rounds up.

> aural: "Round() function always round to lower value"

  Wha--?

I'm sure just a mis-word but INT() always rounds down for positives anyway. 

BTW that's another crazy issue to worry about, rounding with negatives. I'm not sure you always want to add .5 in SMcNeill's Round##()

If not,then add * SGN(num) after that 0.5.  Tweak the behavior to whatever suits your personal needs/desires.
Reply
#10
Actually INT truncates the value dropping everything from the the decimal point. If you need a version of INT that will round both up and down, there is the CINT function.

The one that puzzles me is the fact that, according to the wiki, while there is a _CEIL function there doesn't appear to be a corresponding _FLOOR function.

TR
Reply




Users browsing this thread: 5 Guest(s)