Rounding Numbers with Automation Rules
Three new functions have been added to the Automation Rules functionality. The main purpose of these new functions is to allow numbers to be rounded to a specific number of decimal places.
For example, if there is a UI extension with the fields Units and Cost, and an automation rule is used to calculate the cost per unit, the result could have a long string of numbers behind the decimal separator. In this example, when the Cost is 73 and the number of units is 7, the cost per unit is 10.428571428571429.
It would look ugly when this result was presented in another field. That is why the function round has been added:
10.428571428571429.round = 10
10.428571428571429.round(1) = 10.4
10.428571428571429.round(2) = 10.43
The other two new functions are to_number and to_string. This set has been added mainly to ensure that it is possible to convert values that 4me considers strings to numbers. For completeness, the ability to convert numbers to strings has also been added:
“10.428571428571429”.to_number = 10.428571428571429
10.428571428571429.to_string = “10.428571428571429”
The automation rule in the example would look like this:
The result can be found in the automation trace:
The new operators have been described in the online help page Automation Rule Operators.