Formatting.NumberFormat Property
Gets or sets a number format that specifies how a numeric value is displayed in a cell.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v18.2.Core.dll
Declaration
Property Value
Type | Description |
---|---|
String | A String value specifying a cell number format in the invariant culture (English). |
Remarks
Numbers can appear in cells as percentage, decimal, currency, accounting, or date time values.
To apply a number format, assign the corresponding number format code to the NumberFormat property. Note that you should use only culture-independent (invariant) format strings.
- To specify the number format of an individual cell, use the Cell object’s NumberFormat property that is inherited form the Formatting interface.
- To specify the number format of a range of cells, call the Range.BeginUpdateFormatting method for this range, set the NumberFormat property of the returned Formatting object and call the Range.EndUpdateFormatting method to finalize the modification.
- To share the same number format between multiple cells in a single step, create or modify the style with the NumberFormat property specified as required, and assign this style to Range.Style for the desired cells.
The NumberFormat property allows you to use built-in number formats as well as your own custom ones. For more information, see the How to: Specify Number or Date Format for Cell Content example.
Example
This example demonstrates how to use different number formats to display numeric data using the most appropriate formats.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-e4339
// Display 111 as 111.
worksheet.Cells["A1"].Value = 111;
worksheet.Cells["A1"].NumberFormat = "#####";
// Display 222 as 00222.
worksheet.Cells["B1"].Value = 222;
worksheet.Cells["B1"].NumberFormat = "00000";
// Display 12345678 as 12,345,678.
worksheet.Cells["C1"].Value = 12345678;
worksheet.Cells["C1"].NumberFormat = "#,#";
// Display .126 as 0.13.
worksheet.Cells["D1"].Value = .126;
worksheet.Cells["D1"].NumberFormat = "0.##";
// Display 74.4 as 74.400.
worksheet.Cells["E1"].Value = 74.4;
worksheet.Cells["E1"].NumberFormat = "##.000";
// Display 1.6 as 160.0%.
worksheet.Cells["F1"].Value = 1.6;
worksheet.Cells["F1"].NumberFormat = "0.0%";
// Display 4321 as $4,321.00.
worksheet.Cells["G1"].Value = 4321;
worksheet.Cells["G1"].NumberFormat = "$#,##0.00";
// Display 8.75 as 8 3/4.
worksheet.Cells["H1"].Value = 8.75;
worksheet.Cells["H1"].NumberFormat = "# ?/?";
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the NumberFormat property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.