Numeric Functions
Numeric functions return numeric values (integer, long, float, double, biginteger, bigdecimal). They generally take numeric values as inputs, though some take strings.
Standard Numeric Operators (+ - * /)
These operators take x in {integer, long, float, double, biginteger, bigdecimal}, and their return type is the same as x.
The precision and scale of non-bigdecimal arithmetic functions results match that of Java. The results of bigdecimal operations match Java, except for division, which uses a preferred scale of max(16, dividend.scale + divisor.precision + 1), which then has trailing zeros removed by setting the scale to max(dividend.scale, normalized scale).
Other Numeric Functions
Function | Definition | Data Type Constraint |
---|---|---|
| Absolute value of x | See standard numeric operators above |
| Arc cosine of x | x in {double, bigdecimal}, return type is double |
| Arc sine of x | x in {double, bigdecimal}, return type is double |
| Arc tangent of x | x in {double, bigdecimal}, return type is double |
| Arc tangent of x and y | x, y in {double, bigdecimal}, return type is double |
| Ceiling of x | x in {double, float}, return type is double |
| Cosine of x | x in {double, bigdecimal}, return type is double |
| Cotangent of x | x in {double, bigdecimal}, return type is double |
| Convert x radians to degrees | x in {double, bigdecimal}, return type is double |
| e^x | x in {double, float}, return type is double |
| Floor of x | x in {double, float}, return type is double |
| Format x using format y | x is bigdecimal, y is string, returns string |
| Format x using format y | x is biginteger, y is string, returns string |
| Format x using format y | x is double, y is string, returns string |
| Format x using format y | x is float, y is string, returns string |
| Format x using format y | x is integer, y is string, returns string |
| Format x using format y | x is long, y is string, returns string |
| Natural log of x (base e) | x in {double, float}, return type is double |
| Log of x (base 10) | x in {double, float}, return type is double |
| Modulus (remainder of x / y) | x in {integer, long, float, double, biginteger, bigdecimal}, return type is same as x |
| Parse x using format y | x, y are strings, returns bigdecimal |
| Parse x using format y | x, y are strings, returns biginteger |
| Parse x using format y | x, y are strings, returns double |
| Parse x using format y | x, y are strings, returns float |
| Parse x using format y | x, y are strings, returns integer |
| Parse x using format y | x, y are strings, returns long |
| Value of Pi | return is double |
| x to the y power | x in {double, bigdecimal, biginteger}, return is the same type as x |
| Convert x degrees to radians | x in {double, bigdecimal}, return type is double |
| Return random number in the range 0.0 <= x < 1.0 | return is double; while rand() is pushed down to MySQL, PostgreSQL and Oracle, it's not pushed down to Microsoft SQL Server. |
| Return random number using new generator seeded with x | x is integer, returns double |
| Round x to y places; negative values of y indicate places to the left of the decimal point | x in {integer, float, double, bigdecimal} y is integer, return is the same type as x |
| 1 if x > 0, 0 if x = 0, -1 if x < 0 | x in {integer, long, float, double, biginteger, bigdecimal}, return type is integer |
| Sine value of x | x in {double, bigdecimal}, return type is double |
| Square root of x | x in {long, double, bigdecimal}, return type is double |
| Tangent of x | x in {double, bigdecimal}, return type is double |
| Bitwise AND of x and y | x, y in {integer}, return type is integer |
| Bitwise OR of x and y | x, y in {integer}, return type is integer |
| Bitwise XOR of x and y | x, y in {integer}, return type is integer |
| Bitwise NOT of x | x in {integer}, return type is integer |
Parsing Numeric Data Types from Strings
The CData Virtuality Server offers a set of functions you can use to parse numbers from strings. For each string, you need to provide the formatting of the string. These functions use the convention established by the java.text.DecimalFormat
class to define the formats you can use with these functions. You can learn more about how this class defines numeric string formats from the Oracle Java documentation.
For example, you could use these function calls with the formatting string that adheres to the java.text.DecimalFormat
convention, to parse strings and return the data type you need:
Input String | Function Call to Format String | Output Value | Output Data Type |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The correct format of the input string depends on the server locale. The pattern must follow conventions of U.S. English notation.
Formatting Numeric Data Types as Strings
The CData Virtuality Server offers a set of functions you can use to convert numeric data types into strings. For each string, you need to provide the formatting. These functions use the convention established within the java.text.DecimalFormat
class to define the formats you can use with these functions. You can learn more about how this class defines numeric string formats from the Oracle Java documentation.
For example, you could use these function calls with the formatting string that adheres to the java.text.DecimalFormat
convention, to format the numeric data types into strings:
Input Value | Input Data Type | Function Call to Format String | Output String |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See Also
Check if a String Can Be Cast to a Number Using isNumeric for a ready-to-use CREATE
statement