FORMAT
- Last UpdatedFeb 07, 2023
- 3 minute read
- PI System
- PI OLEDB Enterprise 2019
- Developer
Specify a format for numerical data types:
String FORMAT(x Float64, s String)
String FORMAT (x Float32, s String)
String FORMAT (x Int32, s String)
WString FORMAT (x Float64, s WString)
WString FORMAT (x Float32, s WString)
WString FORMAT (x Int32, s WString)
The format string (2nd parameter) may contain one of the following characters:
|
Character |
Description |
|---|---|
|
# |
Displays a digit. Each instance of the character represents a position for one number. If no value exists in a position, PI OLEDB Enterprise displays a blank space. For example, if you apply this format: #,###, but have a value of , you see nothing but the number . If you have a value of , PI OLEDB Enterprise displays – even though you defined only one placeholder to the left of the thousands separator. |
|
0 |
Displays a digit. Each instance of the character represents a position for one number. If no value exists in a position, PI OLEDB Enterprise displays a zero (). |
|
Thousands and decimal separators |
Indicates where you want to place the thousands and decimal separators. Use the separators defined in your Windows regional settings. |
|
E+, E- –or– e+, e- |
Displays values in scientific (exponential) notation. Use this option when the predefined scientific format does not provide enough room for your values. Use E+ or e+ to display values as positive exponents, and E- or e- to display negative exponents. You must use these placeholders with other characters. For example, suppose you apply the format to a numeric field and then enter 612345. PI OLEDB Enterprise displays . PI OLEDB Enterprise first rounds the number of decimal places down to three (the number of zeroes to the right or left of the decimal separator). Next, PI OLEDB Enterprise calculates the exponent value from the number of digits that fall to the right (or left, depending on your language settings) of the decimal separator in the original value. In this case, the original value would have placed the five-digit value 2013-07-03 cg Is this a typo? And what about the 105 at the end? to the right of the decimal point. For that reason, PI OLEDB Enterprise displays , and the resulting value is the equivalent of 6.123 x 105. |
Examples:
- Returns "5,459.40".
- Returns "334.90".
- Returns "5.00".
- Returns "123.46".
Specify a format for DateTime data type
String FORMAT(x DateTime, s String)
WString FORMAT (x DateTime, s WString)
The format string (2nd parameter) can contain one of the following characters:
|
Character |
Description |
|---|---|
|
d or dd |
Used to display the day of the month as one or two digits. For one digit, use a single placeholder. For two digits, use two placeholders. |
|
M or MM |
Used to display the month as either a one-digit or two-digit number. |
|
MMM |
Used to abbreviate the name of the month to three letters. For example, October appears as Oct. |
|
MMMM |
Used to spell out all month names. |
|
yyyy |
Used to display the 4 digits of the year. |
|
yy |
Used to display the last two digits of the year. |
|
H or HH |
Used to display the hour as one or two digits. 24-hour format. |
|
h or hh |
Used to display the hour as one or two digits. 12-hour format. |
|
tt |
Used to display 12-hour clock values with a trailing AM or PM. |
|
m or mm |
Used to display minutes as one or two digits. |
|
s or ss |
Used to display seconds as one or two digits. |
|
f or ff or fff or ffff or fffff |
Used to display subsecond fractions of up to 5 digits. |
|
/ \ : - . |
Characters, including spaces, allowed as delimiter. |
Examples
- Returns "5:4:23".
- Returns "05:04:23 PM".
- Returns "Jan 27 2011".
- Returns "17:04:23"
- Returns "05:04:23.000".