Round numeric attribute
Event action – Abstract
Purpose: Rounds the numeric value of a numeric attribute identified by Numeric types within the current reference object to a statically defined number of decimal places and updates the attribute with the rounded value.
The Round numeric attribute event action rounds the numeric value of a numeric attribute identified by the Numeric types within the current reference object to a statically defined number of decimal places and updates the attribute with the rounded value.
Unless the current reference object has a numeric attribute with the specified Numeric types or the specified Numeric types is defined as 'plural' (i.e. can contain a list of multiple values), the event action has no effect.
►NOTE◄
Rounding the numeric attribute changes the data of the reference object, but does not imply saving the changed state. Provided the reference object is a standalone entity (and not just a line item of a business transaction object), the event action Save changes later can be used to save the rounded values if required. Otherwise, the changes only apply to the volatile position of the reference object.
When rounding negative decimal numbers, the event action Round numeric attribute rounds up values in the midpoint (i.e. values that fall exactly on the borderline for rounding) in the direction of 0 (towards zero), while for positive decimal numbers, midpoint values are rounded 'away from 0' – i.e. they are also rounded up. If the first decimal in a negative decimal number is a 5, which is not followed by any other digits different from 0, the last valid digit is kept (see the red shaded cells in the following table). In contrast, commercial rounding of the 'midpoint values' rounds away from zero for positive and negative values, so that in borderline cases the absolute amount is rounded up analogously and then provided again with the applicable sign. For positive values, the results of the two rounding rules do not differ.
Output value
Result for
Round numeric attribute
with number of decimal places = 2Result for commercial rounding
to 2 decimal places
+2,345
+2,35
+2,35
-2,345
-2,34
-2,35
►NOTE◄ If 'commercial rounding' must also be achieved for negative 'midpoint values' (e.g. for price reductions or credit notes), the Calculate value event resolver should be used instead of the Round numeric attribute event action to set the rounded attribute value. Within the calculation, the function round ()can be used for rounding, which treats midpoint values as 'commercial'. However, round() does not offer the number of decimal places as a parameter, but always rounds up or down to integers. To round to a defined number of decimal places, we recommend an expression like the following: round(value*(10^decimals))/(10^decimals), where the value to be rounded should be in the variable value and the number of decimal places should be in the variable decimals as a long value.
Configuration
The event action must be executed in the context of the reference object (see also Execute with), which is the 'attribute owner' of the attribute to be rounded.
|
|
Example
When entering Orders, in addition to items for goods, 'service items' (with the Line item type 'Service') should also be created in order to map chargeable services (e.g. assembly/disassembly).
The content of a service item is to be quantified, among other things, by a numeric attribute with the Numeric types 'working hours', the value of which is initially calculated within the data entry form from other data as a 'decimal number' with 'unlimited' precision. For the billing of service items, a 'commercial rounding' of the number of hours per position to one decimal place is agreed, so that the services are evaluated with an accuracy of 6 minutes and individual items with a calculated work content of less than 3 minutes are processed free of charge.
When saving an order, the defined rounding for the 'working hours' per service item is fixed.
An event handling that reacts to the events 'Create' and 'Change' (see Common action event) ensures that an order is present as an input value via a Check type. As the Action on passed rule, a For each loop is configured as shown to the right:
►NOTE◄ The event handling is triggered starting from the 'Create' and 'Change' events, i.e. when 'Saving' the order. Therefore, it is not necessary to Save changes later. This would be necessary, for example, if the rounding should also be triggered for a selected order in an overview by a ribbon macro command triggering a Custom action event. |
|