12-29-2023, 11:54 PM
There is a trick for that which can be accomplished in several ways. Here's an example of a ROUND function (explained in the ZX Spectrum Manual):
This function will round towards +/- infinity.
Use with Round(number, digits)
I'll include it in the math library.
Code:
FUNCTION Round(n as Float, decimals as UByte = 0) AS Float
DIM tmp as Float
DIM d10 = 10^decimals
IF n >= 0 THEN
LET tmp = INT(n * d10 + 0.5)
ELSE
LET tmp = INT(n * d10 - 0.5)
END IF
RETURN tmp / d10
END FUNCTION
Use with Round(number, digits)
I'll include it in the math library.