Number Formats
Results that table cells calculate are easier to read when they share a format. A number format tells TX Text Control ActiveX how to display the result of a cell formula: how many digits and decimal places, with which separators, as a percentage or together with a currency symbol or a word.
Formulas are defined with the TableCellFormula property, as Using Formulas in Table Cells describes. The sections below build number format strings from placeholders, separators, the percentage sign and added text, with an example for each character.
How Number Formats Work
By default, the number format is an empty string, and the cell shows the unformatted value of the calculation. A result without decimal places is displayed as an integer, and a decimal number is displayed with all its decimal places.
To display different results with a common format, set a number format string with the TableCellNumberFormat property. Like the formula, it is set for a cell identified by its table identifier, row and column. A number format string is composed of:
- placeholders,
#and0, - separators,
.and,, - percentage signs,
%, and - other single characters or text.
Reserve Digits With Placeholders
Placeholders stand for the digit positions of the number to format. Two characters are valid placeholders, # and 0. The placeholder 0 fills a position with a zero if no digit of the calculated result occupies it.
| Value | Format | Displayed as |
|---|---|---|
| 7 | # | 7 |
| 789 | # | 789 |
| 1234 | # | 1234 |
| 7 | 000 | 007 |
| 789 | 000 | 789 |
Add Separators
Two separators display a number as a decimal number, with a thousands separator, or both. The separators are rendered with the default decimal and thousands separator signs of the system language: a German system, for example, uses a comma as the decimal sign and a point as the thousands separator.
Decimal Numbers
To display all numbers with decimal places, combine the placeholders with a decimal point (.). The number of placeholders after the point sets the maximum number of decimal places shown. Without a decimal point, results are rounded to the nearest integer.
| Value | Format | Displayed as |
|---|---|---|
| 12.6 | #.## | 12.6 |
| 5 | #.00 | 5.00 |
| 12.6 | #.00 | 12.60 |
| 0.543 | #.00 | 0.54 |
| 17.548 | # | 18 |
Thousands Separator
The second separator is the thousands separator (,). Followed by placeholders, it displays the result with a comma after every third digit. If no placeholder follows the comma, each comma trims the number by three positions before the decimal point.
| Value | Format | Displayed as |
|---|---|---|
| 9876543210.1234 | ,###.## | 9,876,543,210.12 |
| 9876543210 | ,### | 9,876,543,210 |
| 12200000 | #,, | 12 |
| 12200000 | #.0,, | 12.2 |
Show Percentages
The percentage sign has a special meaning. Combined with one or more placeholders, it multiplies the calculated value by 100 and displays it with the percentage sign.
| Value | Format | Displayed as |
|---|---|---|
| 0.52 | #% | 52% |
| 1 | #% | 100% |
| 0.00321 | 0.##% | 0.32% |
| 0.52 | %# | %52 |
Add Characters and Text
There are three ways to combine the calculated value with a single character or with text.
Predefined Characters
The following characters can be combined with a number format string directly:
| Character | Value | Format | Displayed as |
|---|---|---|---|
$ (dollar sign) | 500 | #$ | 500$ |
- (minus sign) | 1 | -#.00 | -1.00 |
+ (plus sign) | 12.345 | +.## | +12.35 |
/ (slash mark) | 4 | \1/# | 1/4 |
( (left parenthesis) | 7 | -(#+\3) | -(7+3) |
) (right parenthesis) | 3 | -(\7+#) | -(7+3) |
: (colon) | 50 | #:"50" | 50:50 |
! (exclamation point) | 6 | #! | 6! |
^ (circumflex accent, caret) | 2.5 | #.00^\2 | 2.50^2 |
& (ampersand) | 0 | #&\1 | 0&1 |
' (apostrophe) | 9 | '#' | '9' |
~ (tilde) | 7.654 | ~#.0 | ~7.7 |
{ (left curly bracket) | 67 | {-#} | {-67} |
} (right curly bracket) | 17 | {+#} | {+17} |
< (less-than sign) | 5 | #<"10" | 5<10 |
> (greater-than sign) | 7.4 | #.00>\6 | 7.40>6 |
= (equal sign) | 5.6 | #>=\6 | 6>=6 |
| Space character | 12 | #.00 $ | 12.00 $ |
Other Characters
Any other character, such as a specific currency symbol, is displayed when you put a backslash directly in front of it:
| Value | Format | Displayed as |
|---|---|---|
| 12.99 | #.00\€ | 12.99€ |
| 42 | \"#\" | "42" |
| 18 | #:\X | 18:X |
Words and Text
To add whole words or text, put them in quotation marks:
| Value | Format | Displayed as |
|---|---|---|
| 29.99 | "EUR"#.00 | EUR 29.99 |
| 4.50 | #.00"€" | 4.50€ |
| 76 | # "Units" | 76 Units |