Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_Round () issue
#14
(05-13-2022, 10:49 AM)SMcNeill Wrote:
(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.

I tried that last night it was a mess!

Today I try removing neg sign, doing the calc and then putting the sign back in, interesting it fails or does bankers rounding! Not what I expected.
Code: (Select All)
Print "N", "Round", "Round Sgn", "Round Neg"
For n## = -1 To 1.00000001 Step .01
    Print n##, RoundOrig(n##, 1), RoundSgn(n##, 1), RoundNeg(n##, 1)
    i = i + 1
    If i Mod 20 = 0 Then Print "zzz... ": Sleep: Cls: Print "N", "Round", "Round Sgn", "Round Neg"
Next

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

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

Function RoundNeg## (num As _Float, toDecPlace As _Unsigned _Byte)
    If num < 0 Then cnum = -1 * num: nFlag = -1 Else cnum = num: nFlag = 1
    RoundNeg## = nFlag * Int(cnum * 10 ^ toDecPlace + .5) / 10 ^ toDecPlace
End Function
b = b + ...
Reply


Messages In This Thread
_Round () issue - by dcromley - 05-11-2022, 04:08 AM
RE: _Round () issue - by bplus - 05-11-2022, 05:32 AM
RE: _Round () issue - by aurel - 05-11-2022, 09:08 AM
RE: _Round () issue - by SMcNeill - 05-11-2022, 09:47 AM
RE: _Round () issue - by OldMoses - 05-11-2022, 10:33 AM
RE: _Round () issue - by dcromley - 05-11-2022, 05:17 PM
RE: _Round () issue - by dcromley - 05-13-2022, 12:45 AM
RE: _Round () issue - by bplus - 05-13-2022, 01:08 AM
RE: _Round () issue - by SMcNeill - 05-13-2022, 10:49 AM
RE: _Round () issue - by bplus - 05-13-2022, 01:55 PM
RE: _Round () issue - by TarotRedhand - 05-13-2022, 11:16 AM
RE: _Round () issue - by SMcNeill - 05-13-2022, 12:02 PM
RE: _Round () issue - by TarotRedhand - 05-13-2022, 01:07 PM
RE: _Round () issue - by SMcNeill - 05-13-2022, 01:21 PM
RE: _Round () issue - by SMcNeill - 05-13-2022, 02:09 PM
RE: _Round () issue - by bplus - 05-13-2022, 06:03 PM
RE: _Round () issue - by SMcNeill - 05-13-2022, 06:20 PM
RE: _Round () issue - by dcromley - 05-13-2022, 09:28 PM



Users browsing this thread: 3 Guest(s)