11-08-2022, 08:20 PM
I had some rounding code fixed for negative numbers with Sgn() in SmallBASIC board at Syntax Bomb this is QB64 version:
Should be OK if stay out of exponential notation.
Code: (Select All)
$Console:Only
For i = 1 To 100
r = Rnd * 200 - 100
Print r, roundDP$(r, 0), roundDP$(r, 1), roundDP$(r, 2), roundDP$(r, 3)
Next
Function roundDP$ (num, digits) ' fixed with sgn 2022-11-08
Dim s$, dot
s$ = _Trim$(Str$(num + (Sgn(num) * .5) * 10 ^ -digits))
dot = InStr(s$, ".")
If dot Then roundDP$ = Mid$(s$, 1, dot + digits) Else roundDP$ = s$
End Function
Should be OK if stay out of exponential notation.
b = b + ...