These custom functions round a number “naturally”. For example, they can be used to round time to 15 minutes, or money to $.25, or just any number to a multiple of another number.

All the functions have the same syntax:

`Round To( ``number`, `precision` )

`Round Down To( ``number`, `precision` )

`Round Up To( ``number`, `precision` )

where `number` is the number to round and `precision` is the number to calculate the appropriate multiple of. For example, `Round To( 13, 5 )`

rounds 13 to the nearest multiple of 5, i.e. 15. The `Round Up To()`

and `Round Down To()`

round the `number` to higher or lower multiple of `precision` respectively.

Functions themselves are very simple:

Round To( number, precision )

Round( number / precision; 0 ) * precision

Round Down To( number, precision )

Floor( number / precision; 0 ) * precision

Round Up To( number, precision )

Ceiling( number / precision; 0 ) * precision

#### How to round time

Don't calculate the number of seconds: use the `Time()`

function instead. For example, to round to an hour:

Round To( Time Field, Time( 1, 0, 0 ) )

to 15 minutes:

Round To( Time Field, Time( 0, 15, 0 ) )

You might also want to make a few constant custom functions: `HOURS`

and `MINUTES`

. These function must return `Time( 1, 0, 0 )`

, `Time( 0, 1, 0 )`

respectively. (You could make a function for seconds, if you need them, but you'll need to select a name carefully, because Seconds is taken already.) With such functions your code will be more readable, like this:

Round To( Time Field, 2 * HOURS )
Round To( Time Field, 0.5 * HOURS )
Round To( Time Field, 15 * MINUTES )
Round To( Time Field, 1/2 * MINUTES )

There's yet another good use of this function: it can help to approximate a number to a common fraction. I'll write about this later.