For conversions between string data-types and numerical data-types, you can supply, on the FORMAT parameter of the CAST function, an optional formatting expression. For conversions from string types, the formatting expression defines how the source string should be parsed to fill the target data-type. For conversions to string types, it defines how the data in the source expression is to be formatted in the target string.
A sequence of zero or more characters. All characters can be used, except the special characters listed in Table 1.
One or more characters to be used as the separator between the whole and decimal parts of a number (the decimal separator). The default decimal separator is a period (.).
A sequence of one or more of the numeric tokens (0 # - + , . ) listed in Table 1.
One or more characters to be used as the separator between clusters of integers, to make large numbers more readable (the grouping separator). The default grouping separator is nothing (that is, there is no grouping of digits or separation of groups).
If multiple grouping separators are used (as in the previous example), the rightmost separator defines the primary size and the penultimate rightmost separator defines the secondary size.
Token | Represents |
---|---|
0 | Any digit, including a leading zero. |
# | Any digit, excluding a leading zero. (See the explanation of the difference between 0 and # that follows this table.) |
. | Decimal separator. |
+ | Prefix of positive numbers. |
- | Prefix of negative numbers. |
, | Grouping separator. |
E/e | Separates the number from the exponent. |
; | Subpattern boundary. |
' | Quote, used to quote special characters. If a quote is needed in output, it must be doubled (''). |
* | Padding specifier. The character following the asterisk is used to pad the number to fit the length of the format pattern. |
The # and 0 characters are used for digit substitution, the difference between them being that a # character is removed if there is no number to replace it with. For example, 10 formatted by the pattern #,##0.00 gives "10.00", but formatted by 0,000.00 gives "0,010.00".
To specify padding characters, use an asterisk. When an asterisk is placed in either of the two chars regions (the prefix and suffix), the character immediately following it is used to pad the output. Padding can be specified only once. For example, a pattern of *x#,###,##0.00 applied to 1234 would give "xxx1,234.00". Applied to 1234567, it would give "1,234,567.00".
Pattern | Input number | Output string |
---|---|---|
+###,##0.00;-###,###,##0.00:groupsep='':decsep=, | 123456789.123 | "+123'456'789,12" |
##0.00 | 1000000 | "1000000.00" |
##0.00 | 3.14159265 | "3.14" |
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ak05615_ |