Products Technologies Demo Docs Blog Support Company

Formatting Numbers in Table Cells

Table cell text can be interpreted as plain text or as a number with an associated number format. This article explains how to use this format and gives examples for various string formatters.

Formatting Numbers in Table Cells

The text type of a table cell can be defined using the TableCellFormat.TextType property which can be either plain text (Standard) or a Number. When defined as text, the string is rendered as is. But when defined as a number, the formatting of the rendered string can be defined. In the following screen video, the table cell text is defined as a number (currency). When changing the cell's text, the associated format is applied automatically when leaving the table cell.

Formatting numbers in Text Control

The table cell format will be applied to any cell content. The following screen video shows a calculated formula that uses the applied string formatter:

Formatting numbers in Text Control

The same is valid for form fields and merge fields that are inserted in a table cell:

Formatting numbers in Text Control

Default Formatting

By default, the rendered text without decimal places is displayed as an integer. If a decimal number is rendered, it is getting rendered with all its decimal places.

The TableCellFormat.NumberFormat property is used to set a number format string, that is a composition of placeholders ('#' or/and '0'), separators ('.' or/and ','), percentage signs ('%') and other single characters or text.

Using Placeholders

Digit placeholders represent positions inside the number to format. As placeholders, 2 kind of characters can be used: '#' and '0' - where the placeholder '0' fills those positions with zeros in case the corresponding position is not reserved by a digit of the calculation's result value.

The following examples show the value, the placeholder and the result:

Number Placeholder Result
7 # 7
123 # 123
7 0 007
123 000 123

Separators

Separators are used to render a number as a decimal number or/and to render with a thousands separator. Depending on the system language, the separator signs are rendered with the system's default digit or thousands separator signs (an English system uses a period to indicate the decimal place and a comma as thousand separator).

Decimal Numbers

To define a format where all numbers are displayed with decimal places, the placeholder must be combined with a digit point ('.'). The number of placeholders after the separator defines the maximum number of decimal places to be rendered. Results are rounded to the next integer value.

Number Format Result
12.7 #.## 12.7
2 #.00 2.00
12.7 #.00 12.70
0.123 #.00 0.12

Thousands Separator

The thousands separator (',') is used in combination with appended placeholders. The result is rendered with a comma at each third digit. If no placeholder is defined after the comma, the number is trimmed by three pre-decimal point positions at each comma location.

Number Format Result
9876543210.1234 ,###.## 9,876,543,210.12
9876543210 ,### 9,876,543,210
12200000 #,, 12
12200000 #.0,, 12.2

Percentages

In order to render percentages, the percentage symbol ('%') can be used in combination with one or more placeholders. The resulting value is multiplied by 100 and shown together with the percentage symbol.

Number Format Result
0.52 #% 52%
1 #% 1%
0.00321 0.##% 0.32%
0.52 %# %52

Additional Text

The resulting number can be combined with a single character or a complete text. The following list shows predefined characters that can be combined with a number format string:

Symbol Number Value Result
$ (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
~ (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 $

Currency Symbols and Others

All other symbols such as currency symbols can be rendered by adding a backslash in front of the character to be rendered:

Number Format Result
12.99 #.00\€ 12.99€
42 \"#\" "42"
18 #:\X 18:X
29.99 "USD" #.00 USD 29.99
76 # "units" 76 units

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.TableCellFormat.NumberFormat Property
  • TXTextControl.TableCellFormat.TextType Property

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETWindows FormsWPF

Inserting MergeBlocks with the DataSourceManager and Applying Table Styles in C#

This article shows how to insert MergeBlocks with the DataSourceManager and how to apply table styles to those tables. The article uses the DocumentServer class to insert MergeBlocks with the…


ASP.NETWindows FormsWPF

Useful Tricks for Working with Tables

When you are working with complex and long tables, it can be useful to know if a table is broken up across multiple pages. These code snippets will help you with various table related tasks.


ASP.NETWindows FormsWPF

Generating Hierarchical Tables from JSON Data in .NET C#

Using TX Text Control, you can generate complex hierarchical tables directly from JSON data. This article explains the code and logic behind it.


ASP.NETWindows FormsWPF

Extension Method: Converting Tables to Tabs in C#

When you export documents to formats that don't support tables, such as ANSI text, you can convert those tables to tabs. This article describes how to convert a table object to tabs using a C#…


ASP.NETJavaScriptWindows Forms

Auto-Sizing Tables Proportionally

This article shows how to resize a table to fit the complete page by adjusting each column proportionally.