IV. Rounding Numbers

 

Using The round Function:

variable = round(Value, Multiple);

The above rounds the number (Value) to the nearest multiple (Multiple).

Mental Illustration: The round function divides the number line starting from zero (in both directions) into partitions of length multiple. If the value lies anywhere at or above one of the midpoints between any two partition points it will be rounded up to the nearest partition point that lies above the value. If  the value lies anywhere below the midpoint between any two partition points it will be rounded down to the nearest partition point below the value.

Example:

rounded_value = round(0.5, 1);

// rounds 0.5 to up to 1, which is the nearest partition point above 0.5,

rounded_value = round(0.4, 1);

// round 0.4 down to 0, which is the nearest partition point below 0.4

Using The rounddown Function:

variable = rounddown(Value, Multiple);

The above rounds the number (value) to the nearest multiple less than or equal to value.

Mental Illustration: The rounddown function devides the number line starting from zero (in both directions) into partitions

of length multiple. If the value lies between two partition points it will be rounded to the point below it. If it lies on a partition point it will be rounded to the partition points value.

Example:

rounded_value = rounddown(0.5, 1);  
// rounds 0.5 to down to 0, which is the nearest partition point on or below 0.5

rounded_value = rounddown(0.0, 1);  
// round 0.0 down to 0, which is the nearest partition point on or below 0.0

rounded_value = rounddown(0.9, 1);  
// round 0.9 down to 0, which is the nearest partition point on or below 0.9

All of the above Values, namely 0.0, 0.5, and 0.9 round down to 0.