Skip to main content

The "round_to" Function

Syntax#

round_to(value, multiple);
ArgumentTypeDescription
valuerealThe value to round
multiplerealThe number to round to, as a multiple

Description#

Rounds to a multiple of the specified number (rather than to the nearest whole) and returns the result. Unlike normal rounding, rounding to fractional values is supported.

Note that this script uses "banker's rounding", meaning if a value is exactly half the multiplier, it will round to the nearest even number.

Also note that the multiplier should always be positive. The value to round can be either positive or negative.

Example#

score = round_to(score, 10);