Spreadsheet format codes
Use a spreadsheet code when you need a precise mask rather than the preset options. With the Pro setup, use kind: 'code' instead of kind: 'preset':
grid.columns = [{ prop: 'amount', name: 'Amount', dataGridFormat: { value: { kind: 'code', formatCode: '#,##0.00', locale: 'en-US', } },}];Choose a mask
Section titled “Choose a mask”The following examples use en-US unless the code carries a locale token:
| Use | Raw value | formatCode | Display |
|---|---|---|---|
| Grouped decimals | 1234.5 | #,##0.00 | 1,234.50 |
| Optional decimal digits | 12.5 | 0.## | 12.5 |
| Padded numeric label | 42 | 00000 | 00042 |
| Percent ratio | 0.125 | 0.0% | 12.5% |
| Scientific | 1200 | 0.00E+00 | 1.20E+03 |
| Rational fraction | 1.25 | # ?/? | 1 1/4 |
| Fixed denominator | 1.375 | # ?/8 | 1 3/8 |
| Millions for BI | 1500000 | 0.0,,"M" | 1.5M |
| Literal unit | 12 | 0" kg" | 12 kg |
| German euro pattern | 1234.5 | [$€-407]#,##0.00 | €1.234,50 |
| Elapsed time in days | 2.25 | [h]:mm:ss | 54:00:00 |
0 requires a digit; # makes it optional; ? reserves digit space. Trailing commas scale the display by thousands without changing the source. Quoted literals add labels without converting units. Fractions approximate a value for display; they do not store rational arithmetic.
Positive, negative, zero, text
Section titled “Positive, negative, zero, text”Up to four semicolon-separated sections describe positive, negative, zero and text values:
const value = { kind: 'code' as const, formatCode: '0.00;[Red](0.00);"zero";"value: "@',};This displays -12.5 as (12.50) in red, 0 as zero, and hello as value: hello. Conditional sections such as [Red][<0]0.0;0.0 choose a pattern by value. Supported code families also include date/time tokens, elapsed [h]/[m]/[s], escaped literals, named/indexed colors, _ spacing and * fill. Locale tokens override the fallback locale.
Validate and preserve the data contract
Section titled “Validate and preserve the data contract”import { validateDataGridFormatCode } from '@revolist/revogrid-pro';
const diagnostics = validateDataGridFormatCode('#,##0.00');if (diagnostics.length) console.log(diagnostics);Malformed codes fall back to raw display. RevoGrid supports common spreadsheet families; do not assume every Excel feature or another BI tool’s mask grammar is identical. Test imported codes against representative positive, negative, zero, blank and text values.
A code is display metadata, not an input mask. Code formats do not enable the numeric-preset save conversion. Use editing validation or a numeric editor. A padded account code or phone number should usually be a source string so leading zeros survive imports and exports. Use the time guide before assigning dates or elapsed values.
For runtime format state and native workbook number formats, see Format Cells and Excel cell formatting. Power BI has its own custom format rules; translate the intent rather than assuming masks are interchangeable.