Original Author Paul Laughton, 2011
Page 58
De Re BASIC!
FRAC(n) is equivalent to "n - INT(n)".
MOD(<nexp1>, <nexp2>)
Returns the remainder of <nexp1> divided by <nexp2>. If <nexp2> is 0, the function generates a runtime
error.
ROUND(<value_nexp>{, <count_nexp>{, <mode_sexp>}})
In it simplest form, ROUND(<value_nexp>), this function returns the closest whole number to <nexp>.
You can use the optional parameters to specify more complex operations.
The <count_nexp> is an optional decimal place count. It sets the number of places to the right of the
decimal point. The last digit is rounded. The decimal place count must be >= 0. Omitting the parameter
is the same as setting it to zero.
The <mode_sexp> is an optional rounding mode. It is a one- or two-character mnemonic code that tells
ROUND() what kind of rounding to do. It is not case-sensitive. There are seven rounding modes:
Mode:
Meaning:
-3.8
-3.5
-3.1
3.1
3.5
3.8
"HD"
Half-down
-4.0
-3.0
-3.0
3.0
3.0
4.0
"HE"
Half-even
-4.0
-4.0
-3.0
3.0
4.0
4.0
"HU"
Half-up
-4.0
-4.0
-3.0
3.0
4.0
4.0
"D"
Down
-3.0
-3.0
-3.0
3.0
3.0
3.0
"U"
Up
-4.0
-4.0
-4.0
4.0
4.0
4.0
"F"
Floor
-4.0
-4.0
-4.0
3.0
3.0
3.0
"C"
Ceiling
-3.0
-3.0
-3.0
4.0
4.0
4.0
In this table, "down" means "toward zero" and "up" means "away from zero" (toward ±)
"Half" refers to behavior when a value is half-way between rounding up and rounding down(x.5
or -x.5). "Half-down" rounds x.5 towards zero and "half-up" rounds x.5 away from zero.
"Half-even" is either "half-down" or "half-up", whichever would make the result even. 4.5 and
3.5 both round to 4.0. "Half-even" is also called "banker's rounding", because it tends to average
out rounding errors.
If you do not provide a <mode_sexp>, ROUND() adds +0.5 and rounds down (toward zero). This is legacy
behavior, copied from earlier versions of BASIC!. ROUND(n) is NOT the same as ROUND(n, 0).
ROUND() generates a runtime error if <count_nexp> < 0 or <mode_sexp> is not valid.
Examples:
pi = ROUND(3.14159)
% pi is 3.0
pi = ROUND(3.14159, 2)
% pi is 3.14
pi = ROUND(3.14159, , "U")
% pi is 4.0
pi = ROUND(3.14159, 4, "F")
% pi is 3.1415
negpi = ROUND(-3.14159, 4, "D")
% negpi is -3.1416