Math operations - script to Java component
For the Math operations, not all of the script operations from the Script API are implemented in the Java™ API. Alternative Java code is provided for those script operations that are not implemented in the Java API.
Script operation | Alternative Java code |
---|---|
max() | new Double( Java.lang.Math.max(a.intValue(), b.intValue()) |
min() | new Double( Java.lang.Math.min(a.intValue(), b.intValue()) |
rand() | new
Integer(Math.round((float)Math.floor (Math.random()*max.intValue())) |
reformatDouble() | com.ibm.icu.text .DecimalFormat dfFormat = new DecimalFormat(“decimalformate”); String sReformattedNumber = dfFormat.format(numberTobeFormatted); |
toDouble() | new Double(string.intValue()); |
toInteger() | new Integer(string.intValue); |
Note: Rounding and precision truncation conforms to the Java IEEE 754 standard, which rounds digit
to the nearest even digit when the decimal number binary representation contains fractional
parts.