(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