Targeted JSON Pointer: Retrieve the Data as a Numeric Type
using Targeted JSON Pointer..
ASTER::EXPRESSION::JSON::Targeted JSON Pointer: Get as a value of numeric
Retrieve data as a numeric type from the array elements you specified in a JSON array located at a pre-targeted path.
- Relevant URL : Set the Targeted JSON Pointer
You can retrieve values cast to a numeric type from a Boolean type.
{
"example":
[
true,
false
]
}| Boolean Value | Value After Conversion to Numeric |
|---|---|
true |
1 |
false |
0 |
Data registered as a string type will also be retrieved as a numeric type whenever possible.
In JSON specifications, numeric types are integers (int) and floating-point numbers (double). However, when exchanging values between ASTER and CF25, the support for floating-point numbers is limited to float according to CF25 specifications.
The float type can represent numbers with a total of 7 digits, including both the integer part and the fractional part. While this precision is practically sufficient, its representable range is significantly narrower compared to the double type.
The upper limit of the signed int type has been confirmed to be ±2,147,483,647.
Parameter
Assume the following JSON data is loaded into memory, and specify an array element.
{
"numeric":
[
[
-100,
"2147483647",
19.0E-2,
19.0E-5,
19.0E-6,
true
]
]
}"/numeric/0"0ExNumAsTgtArIdx( "ASTER", 0 )| argument | result | Details |
|---|---|---|
0 |
-100 |
Value retrieved from "/numeric/0/0" |
1 |
2147483647 |
Upper limit of the signed int type, converted from a string |
2 |
0.19 |
Scientific notation (19.0 × 10⁻²) |
3 |
0.00019 |
Scientific notation (19.0 × 10⁻⁵) |
4 |
1.9e-05 |
Rounding error: 0.000019 rounded internally |
5 |
1 |
Boolean converted to a numeric type |
19.0E-6 is rounded to 1.9e-05.
This is consistent with the specifications of the CF25 Expression Editor, where values are rounded to the nearest representable value within the range of significant digits.
0.000019 (or 19.0E-6) falls within the range of the float type in C language. However, in CF25, 19.0E-6 is internally rounded to the nearest representable value within the significant digits range, which is 1.9e-05.
Notes.1
Regarding scientific notation and rounding errors:
E-5 represents scientific notation, equivalent to E^-5. 19.0 * 10 ^ -5 is calculated on a computer as follows.
float a = 19.0;
float b = 0.00001; // 10 ^ -5
double c = a * b; // 0.00018999999999999998
The decimal fraction (e.g., 0.00001) becomes an infinite series in binary and is approximated within a limited number of bits. This approximation introduces small errors in calculations, resulting in
19.0 × 10⁻⁵being computed as0.00018999999999999998instead of the expected exact value0.00019.
A value of the double type (double-precision) is rounded to 0.00019 when converted to a single-precision floating-point number.
Notes.2
Logic for converting string types to numeric types
As a simple solution, ASTER casts to a float type when the string contains a ..
Decimal notation, such as ".019", is supported.
However, this method encounters issues with scientific notation. For example, 1E-3 equals 0.001, but ASTER cannot interpret the string "1E-3" as a floating-point number.
"1E-3"is converted to1in ASTER.
Notes.3
CF25 Specifications
There is no reliable method for handling doubles other than converting them to strings for sending and receiving. Within extensions, numbers are typically handled as doubles, and only the calculation results are rounded to floats before being returned to CF25.
