Numeric Format Strings

You can create a standard or custom numeric format string, which consists of one or more numeric specifiers, to define how to format numeric data using Composite Formatting of strings. .

Standard Numeric Format Strings

Standard numeric format strings are used to format common numeric types. A standard numeric format string takes the form Axx, where:

  • A is a single alphabetic character called the format specifier. Any numeric format string that contains more than one alphabetic character, including white space, is interpreted as a custom numeric format string. For more information, refer to Custom Numeric Format Strings (see below).
  • xx is an optional integer called the precision specifier. The precision specifier ranges from 0 to 99 and affects the number of digits in the result. Note that the precision specifier controls the number of digits in the string representation of a number. It does not change the value (round) the number (or variable) that is passed in. The variable or value that is passed in will be the same following the call as it was before the call. However, the returned value is rounded to the number of digits specified by the precision specifier.

The following table describes the standard numeric format specifiers and displays sample output produced by each format specifier. Note that the string representations of numeric values typically vary by culture. See the Example section for EasyLanguage code samples.

Specifier Name Description Example
"C" or "c" Currency
  • Result: A currency value.
  • Supported by: All numeric types.
  • Precision specifier: Number of decimal digits.

1234.5678 ("C") -> $1,234.57

1234.5678 ("C4") -> $1,234.5678

"D" or "d" Decimal
  • Result: Integer digits with optional negative sign.
  • Supported by: Integral types only.
  • Precision specifier: Minimum number of digits.

1234 ("D") -> 1234

-1234 ("D6") -> -001234

"E" or "e" Exponential
  • Result: Exponential notation.
  • Supported by: All numeric types.
  • Precision specifier: Number of decimal digits.

1052.0329112756 ("E") -> 1.052033E+003

-1052.0329112756 ("e2") -> -1.05e+003

"F" or "f" Fixed-point
  • Result: Integral and decimal digits with optional negative sign
  • Supported by: All numeric types.
  • Precision specifier: Number of decimal digits.

1234.567 ("F") -> 1234.57

1234 ("F1") -> 1234.0

-1234.56 ("F4") -> -1234.5600

"G" or "g" General
  • Result: The more compact of either fixed-point or scientific notation.
  • Supported by: All numeric types.
  • Precision specifier: Number of significant digits.

-123.456 ("G") -> -123.456

-1.234567890e-25 ("G") -> -1.23456789E-25

"N" or "n" Number
  • Result: Integral and decimal digits, group separators, and a decimal separator with optional negative sign.
  • Supported by: All numeric types.
  • Precision specifier: Desired number of decimal places.

1234.567 ("N") -> 1,234.57

1234 ("N1") -> 1,234.0

-1234.56 ("N3") -> -1,234.560

"P" or "p" Percent
  • Result: Number multiplied by 100 and displayed with a percent symbol.
  • Supported by: All numeric types.
  • Precision specifier: Desired number of decimal places.

1 ("P") -> 100.00 %

-0.39678 ("P1") -> -39.7 %

"X" or "x" Hexadecimal
  • Result: A hexadecimal string.
  • Supported by: Double, Int, and Int64
  • Precision specifier: Minimum number of digits in result.

255 ("X") -> FF

255 ("x4") -> 00ff

123456789 ("X4") -> 75BCD15
Any other single character Unknown Throws a format exception at runtime. Error
Custom Numeric Format Strings

The following table describes the custom numeric format specifiers and displays sample output produced by each format specifier. Note that the string representations of numeric values typically vary by culture. See the Example section for EasyLanguage code samples.

Specifier Name Description Examples
"0" Zero placeholder Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string. 1234.5678 ("00000") -> 01235
0.45678 ("0.00") -> 0.46
"#" Digit placeholder Replaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.

Note that no digit appears in the result string if the corresponding digit in the input string is a non-significant 0. For example, 0003 ("####") -> 3.
1234.5678 ("#####") -> 1235
0.45678 ("#.##") -> .46

"." Decimal point Determines the location of the decimal separator in the result string. 0.45678 ("0.00") -> 0.46
"," Group separator and number scaling Serves as both a group separator and a number scaling specifier. As a group separator, it inserts a localized group separator character between each group. As a number scaling specifier, it divides a number by 1000 for each comma specified.
Group separator specifier:
2147483647 ("##,#") -> 2,147,483,647
Scaling specifier:
2147483647 ("#,#,,") -> 2,147
"%" Percentage placeholder Multiplies a number by 100 and inserts a percentage symbol in the result string.
0.3697 ("%#0.00") -> %36.97
0.3697 ("##.0 %") -> 37.0 %
"‰" Per mille placeholder Multiplies a number by 1000 and inserts a per mille symbol in the result string. 0.03697 ("#0.00‰") -> 36.97‰
"E0"

"E+0"

"E-0"

"e0"

"e+0"

"e-0"
Exponential notation If followed by at least one 0 (zero), formats the result using exponential notation. The case of "E" or "e" indicates the case of the exponent symbol in the result string. The number of zeros following the "E" or "e" character determines the minimum number of digits in the exponent. A plus sign (+) indicates that a sign character always precedes the exponent. A minus sign (-) indicates that a sign character precedes only negative exponents.

987654 ("#0.0e0") -> 98.8e4
1503.92311 ("0.0##e+00") -> 1.504e+03
1.8901385E-16 ("0.0e+00") -> 1.9e-16
"\" Escape character Causes the next character to be interpreted as a literal rather than as a custom format specifier.

987654 ("\###00\#") -> #987654#
'string'

"string"
Literal string delimiter Indicates that the enclosed characters should be copied to the result string unchanged. 68 ("# ' degrees'") -> 68 degrees
68 ("#' degrees'") -> 68 degrees
; Section separator Defines sections with separate format strings for positive, negative, and zero numbers.

12.345 ("#0.0#;(#0.0#);-\0-") -> 12.35
0 ("#0.0#;(#0.0#);-\0-") -> -0-
-12.345 ("#0.0#;(#0.0#);-\0-") -> (12.35)

12.345 ("#0.0#;(#0.0#)") -> 12.35

0 ("#0.0#;(#0.0#)") -> 0.0

-12.345 ("#0.0#;(#0.0#)") -> (12.35)
Other All other characters The character is copied to the result string unchanged. 68 ("# °") -> 68 °
Example

The following shows the use of composite formatting.  

Import Example

Composite formatting sample print output

  1. Click on the Import Example link to import the example into TradeStation.   
  2. Go to the TradeStation platform and create a Chart window.  Use the Insert - Indicator menu sequence and Add !ex_CompositeFormatting to the chart window. Select the View > EasyLanguage Print Log to see the text output.
  3. To review or modify the example code, go to the TS Development Environment and open indicator !ex_CompositeFormatting in the EasyLanguage Editor.