Number modifiers are natural language functions for manipulating numeric values. These functions are useful for tasks that involve transforming one thing into another, such as rounding a number, formatting it for display, and other similar tasks.
This is the summary of the available number modifiers for quick reference:
|Round||Round a number to the nearest integer.|
This modifier rounds a number to the nearest whole number, based on the rounding mode and scale that you specify.
When you round a number, the output type remains the same as the input. For example, if you round a float value, the result will still be a float value. Rounding an integer has no effect, so the output is the same as the input.
This modifier has the following syntax:
You can optionally specify a rounding mode:
/*<value>*/ rounded /*<mode>*/
And also a scale:
/*<value>*/ rounded with scale of /*<scale>*/
The /*<mode>*/ is a literal word that specifies the rounding mode and cannot be specified dynamically using expressions.
Here is a list of the supported modes:
|up||Round away from zero. For example, 2.5 becomes 3 and -2.5 becomes -3. This is the default rounding mode.|
|down||Round towards zero. For example, 2.5 becomes 2 and -2.5 becomes -2.|
|half up||Round to the nearest integer, with .5 rounded up. For example, 2.5 becomes 3, and -2.5 becomes -3.|
|half down||Round to the nearest integer, with .5 rounded down. For example, 2.5 becomes 2, and -2.5 becomes -2.|
|half even||Round to the nearest integer, with .5 rounded to the nearest even number. For example, 2.5 becomes 2, and 3.5 becomes 4.|
|half odd||Round to the nearest integer, with .5 rounded to nearest odd number. For example, 2.5 becomes 3, and 3.5 becomes 3.|
These are the supported parameters:
The number to round.
A non-negative integer that specifies the number of digits to the right of the decimal point.
Here is a basic example of how to round a number using the default rounding mode:
10.5 rounded // 11
For more control, you can specify the rounding mode:
10.5 rounded down // 10
If you want to round a number to a specific number of decimal places, you can specify the scale:
10.136 rounded with scale of 2 // 10.14