FORMAT_NUM function
Functions
FORMAT_NUM{SIZE[,SIGN[,DECIMAL]]}
This function converts the target character string based on the specified numeric format (the minimum number of digits, the handling of signs, and the number of digits after the decimal point).
An error occurs if the target character string cannot be handled as a numeric character string. Note that null characters are handled as 0.
Parameters
SIZE
Specify a number from 1 to 99 as the minimum number of digits to be output. (This parameter cannot be omitted.)
If the number of digits of the input string is smaller than the specified number of digits, the digits are padded with zeros.
If the number of digits of the input string is larger than the specified number of digits, all the integral digits are output.
Note that signs are counted as part of the digits.
SIGN
Specify how to output the signs. (This parameter can be omitted).
The table below explains the format symbols that can be specified.
Setting value |
Meaning |
---|---|
Null (default) |
Does not output any signs. |
+- |
Outputs signs. |
- |
Outputs only the minus sign. |
Other than the above |
Error |
DECIMAL
Specify a number from 0 to 9 as the number of digits in the decimal part. (This parameter can be omitted).
If 0 is specified, only the integral part is output. If this parameter is omitted, 0 is set.
If the number of digits of the decimal part of the input is smaller than the specified number of digits, the digits are padded with zeros.
If the number of digits of the decimal part of the input exceeds the specified number of digits, the excessive digit nearest the decimal point is rounded off.
Input/output relationships
The table below explains the relationships between the field type of input data and the field type of output data.
Input |
Output |
---|---|
X |
Numeric character string |
N |
Error |
M |
Numeric character string |
D |
Numeric character string |
W |
Numeric character string |
9 (numeric character string) |
Numeric character string |
I |
Error |
Example
Input |
FORMAT_NUM specification |
Result |
---|---|---|
-1234.5678 |
FORMAT_NUM{5,+-,0} |
-1235 |
-1234.5678 |
FORMAT_NUM{5,-,1} |
-1234.6 |
-1234.5678 |
FORMAT_NUM{5,,2} |
1234.57 |