|
|
Using floating point values in scriptingThe following examples demonstrate how floating point values can be used within the scripting code you create. All of the following examples are implemented in JavaScript. While the same examples may be repeated using several other scripting languages, the syntax may be different: o The simple script below assigns floating point values to two variables in order to find their average. This code may be executed from any scripting control point. The log file output will always read "r = 3.85".
var a = 5.5; o The next example extends the simple script presented above. Consider you have in your input Connector a multiple values attribute called "Marks" containing string values (java.lang.String) representing floating point values (a common situation in real life). This attribute is mapped to an attribute in your output Connector called "AverageMark", which holds the average value of the "Marks" attribute's values. Below is the code used to correctly map these attributes: 01. var
values =
work.getAttribute("Marks").getValues(); 11. avr_attr =
system.newAttribute("AverageMark"); In this example, the core of the floating point processing takes place at line 7 . It first parses the attributes's string value [ java.lang.Double(values[i]) ] and then creates a numeric value to use in scripting [ new Number(java.lang.Double(values[i])) ]. Line 10 calculates the average value and assigns it to a variable. Lines 11-13 assign the calculated value as the output attribute value, thereby completing the mapping operation.
|
|
|