_Round () issue - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: _Round () issue (/showthread.php?tid=389) Pages:
1
2
|
_Round () issue - dcromley - 05-11-2022 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 ] RE: _Round () issue - bplus - 05-11-2022 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. RE: _Round () issue - aurel - 05-11-2022 Round() function always round to lower value RE: _Round () issue - SMcNeill - 05-11-2022 Easiest solution I've found for this type of thing -- just write your own Round function: Code: (Select All) Print _Pi Can easily round to whatever decimal point you want with the above. RE: _Round () issue - OldMoses - 05-11-2022 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 RE: _Round () issue - dcromley - 05-11-2022 [ meaning: "got it"; "thanks"; "am processing"; "reserve the right to continue later" ] RE: _Round () issue - dcromley - 05-13-2022 > 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--? RE: _Round () issue - bplus - 05-13-2022 (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." 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##() RE: _Round () issue - SMcNeill - 05-13-2022 (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." If not,then add * SGN(num) after that 0.5. Tweak the behavior to whatever suits your personal needs/desires. RE: _Round () issue - TarotRedhand - 05-13-2022 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 |