Format strings for numbers can contain:
Specifier |
Represents |
|---|---|
0 |
0 format character prints significant digits or zero if there is not a significant digit. |
# |
# format character prints significant digits only. |
_ |
Allow the space required for the character following the underscore. For example, when you follow an underscore with a right parenthesis, such as _), positive numbers line up correctly with negative numbers that are enclosed in parentheses. |
. |
Decimal point. The first "." character in the format string determines the decimal separator in the formatted value; additional "." characters are ignored. |
, |
Thousand separator. If the format string contains one or more "," characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of "," characters in the format string does not affect the output, except to indicate that thousand separators are wanted. If the format string terminates with "," the number is rounded for display formatted to thousands. |
E+ |
Scientific notation. If any of the strings "E+", "E-", "e+", or "e-" are contained in the format string, the number is formatted using scientific notation. A group of up to four "0" characters can immediately follow the "E+", "E-", "e+", or "e- " to determine the minimum number of digits in the exponent. The "E+" and "e+" formats cause a plus sign to be output for positive exponents and a minus sign to be output for negative exponents. The "E-" and "e-" formats output a sign character only for negative exponents. |
'xx'/"xx" |
Characters enclosed in single or double Quotes are output as-is, and do not affect formatting. |
; |
Separates sections for positive, negative, and zero numbers in the format string. |
[color] |
Colours can be specified in square brackets as for Color Properties in Report Designer. |
Format String Sections
To allow different formats for positive, negative, and zero values, the format string can contain between one and three sections separated by semicolons. If the section for negative values or the section for zero values is empty, that is, if there is nothing between the semicolons that delimit the section, the section for positive values is used instead. If the section for positive values is empty, or if the entire format string is empty, the value is formatted using general floating-point formatting. General floating-point formatting is also used if the value has more than 18 digits to the left of the decimal point and the format string does not specify scientific notation.
Sections |
Description |
|---|---|
One section |
The format string applies to all values. |
Two sections |
The first section applies to positive values and zeros, and the second section applies to negative values. |
Three sections |
The first section applies to positive values, the second applies to negative values, and the third applies to zeros. |
When domain formatting is used and all three parts (positive; negative; zero) are explicit, the zero formats as a dash (-). For example:
Format String |
Output for zero |
|---|---|
Percent 1 |
0.0% |
Percent 1;Percent 1;Percent 1 |
- |
Add Spaces for Alignment
To create a space the width of a character in a number format, use an underscore followed by the character.
For example, to align positive numbers correctly with negative numbers that are enclosed in parentheses, and show zero as a dash positioned in the decimal point position:
,0.00_);(0.00);"-"_0_0_)
Currency
For currency numbers, use the $ sign in the format string to imply the currency symbol and position from Accredo for that currency, otherwise the symbol and position for the base currency are used. If an explicit currency symbol is specified, this will override the currency symbol setting.
Decimals Grouping
If explicit , (comma) is specified, the base grouping will be used. If explicit decimal grouping is specified, this will override the decimal grouping setting.
Format String Examples
The last three examples below use Domains for formatting.
Note: Domain formatting for Amounts and Prices is context sensitive drawing Decimal places, grouping and currency symbols from FX Currency and formatting per context from Company > Configuration > Settings > Currency Format tab.
The default for the MaxBasic context is not to format with Currency Symbol or Grouping. We recommend leaving the MaxBasic default for CurrencySymbol False, NegativeFormat Leading and Grouping None and being explicit with a Format string if you require a different output.
Format string |
1234 |
-1234 |
0.5 |
0 |
|
1234 |
-1234 |
0.5 |
0 |
0 |
1234 |
-1234 |
0 |
0 |
0.00 |
1234.00 |
-1234.00 |
0.50 |
0.00 |
#.## |
1234 |
1234 |
-.5 |
|
,0.00 |
1,234.00 |
-1,234.00 |
0.50 |
0.00 |
,0.00_);(,0.00) |
1,234.00 |
(1,234.00) |
0.50 |
0.00 |
,0.00;;Zero |
1,234.00 |
-1,234.00 |
0.50 |
Zero |
0.000E+00 |
1.234E+03 |
-1.234E+03 |
5.000E-01 |
0.000E+00 |
#.###E-0 |
1.234E3 |
-1.234E3 |
5E-1 |
0E0 |
Quantity;;# |
1234.0 |
-1234.0 |
0.5 |
|
Discount;(Discount);"" |
1234.00% |
(1234.00%) |
0.50% |
|
[blue]Amount;[red](Amount);Amount |
$1234.00 |
|
|
|
$,0,_)K;($,0,)K |
$1 K |
($1)K |
|
|