The convertNumeric32() function
Converts an input numeric value from its current storage size, precision, and scale to a 32-bit numeric with a new precision and scale.
Description
int32 convertNumeric32(int32 value, int curPrec, int curScale, int
desiredPrec, int desiredScale);
int32 convertNumeric32(int64 value, int curPrec, int curScale, int
desiredPrec, int desiredScale);
int32 convertNumeric32(CNumeric128 value, int curPrec, int curScale,
int desiredPrec, int desiredScale);
value specifies the integer part of the input numeric, which can be either a 32-bit, 64-bit, or 128-bit value.
curPrec and curScale specify the current precision and scale for the input numeric specified in value.
desiredPrec and desiredScale specify the new precision and scale for the converted numeric. For a 32-bit numeric, the desiredPrec value can range from 1 to 9, and the desiredScale value can range from 0 to (9-desiredPrec). If your wanted precision is in the range of 10 to 18, use the convertNumeric64 function, or if the wanted precision is in the range of 19-38, use the convertNumeric128 function. This helps to ensure that you select the right storage size for the resulting integer part of the numeric.
Returns
The function returns a 32-bit integer that is compatible with the wanted precision and scale values.
Throws
Numeric value out of rangeusually indicates that the input value is outside the range of the current precision and scale values, or outside the range of a 128-bit integer.overflow in 128-bit arithmeticfor the convertNumeric32 and convertNumeric64 functions, indicates that the precision is larger than the data type supports.%d: precision range error, exponentusually indicates that a precision value is greater than the data type supports, or that the precision is greater than the maximum of 38 for a 128-bit integer.