Skip to content

dos_round

Dale Fugier edited this page Jul 1, 2026 · 1 revision

Rounds a decimal number to an integer.

There are many different ways to round floating point values to integers. DOSLib provides a couple of basic ones in dos_ceil and dos_floor. This function provides several other useful methods for rounding numbers.

Note, there are two general categories of rounding algorithm: those that are symmetric about zero and those that are biased in some way.

Syntax

(dos_round number [mode])

Parameters

number

The number to round.

mode

The rounding method

Method Description
0 Symmetric round up. Bias is away from zero.
1 Symmetric round down. Bias is towards zero.
2 Common round half up. Bias is to positive infinity.
3 Common round half down. Bias is to negative infinity.
4 Symmetric round half up. Bias is away from zero.
5 Symmetric round half down. Bias is towards zero.
6 (Default) Round half even (Banker's rounding). No bias.
7 Round alternate. No bias for sequential calls.
8 Symmetric round alternate. No bias for sequential calls.
9 Random round. Bias toward the random number generator.

Returns

The rounded number if successful.

nil on error.

Example

Command: (dos_round 3.14)
3

Command: (dos_round 3.64)
4

Clone this wiki locally