Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_Round () issue
#17
(05-13-2022, 06:03 PM)bplus Wrote: Expected RoundNeg##(n, 1) to round negs like pos and then add a - sign to the calc.

Like this?

Code: (Select All)
Screen _NewImage(1024, 720, 32)

For i = 10.5 To -10.5 Step -.25
    If i = Int(i) Then Print
    Print i, Round(i, 0),

Next

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

If that's not what you're looking for, you'll need to spell it out with some numbers and what you expect to see them become.

+0.75 = +1
+0.5 = +1
+0.25 = 0
-0.25 = 0 
-0.5 = -1
-0.75 = -1

Or this formula as well, if you prefer:
Code: (Select All)
Function Round## (num As _Float, toDecPlace As _Unsigned _Byte)
    Round = Sgn(num) * Int(Abs(num) * 10 ^ toDecPlace + .5) / 10 ^ toDecPlace
End Function
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  keyboard issue ? SHIFT + TAB not detected (linux) Herve 13 1,796 08-27-2025, 09:47 AM
Last Post: Herve
  OpenGL Lighting Issue aadityap0901 11 2,056 10-02-2024, 12:57 PM
Last Post: aadityap0901
  Another Mouse Issue? NakedApe 17 2,976 05-02-2024, 03:16 AM
Last Post: NakedApe
  A Perplexing Issue NakedApe 5 1,495 08-04-2023, 06:21 PM
Last Post: OldMoses
  HELP! I find an issue using _DEVICES! TempodiBasic 10 1,955 05-02-2023, 09:57 AM
Last Post: TempodiBasic

Forum Jump:


Users browsing this thread: 1 Guest(s)