Skip to content

NumberCell

NumberCell is a built-in display-only cell that formats numeric values into readable text. It supports decimal places, thousands separators, prefix/suffix, sign display, percentages, unit abbreviation (万/亿, K/M/B) and empty-value placeholders. It is commonly used for market quotes, monetary amounts and statistical data.

Basic Usage

Create a NumberCell component via the createNumberCell factory function and use it as customCell. It is recommended to set align: 'right' on the column for numeric alignment.

loading
ts
const { NumberCell } = createNumberCell({ decimals: 2 });

const columns = [
    { title: '现价', dataIndex: 'price', align: 'right', customCell: NumberCell() },
];

Different formats per column

Each createNumberCell fixes one format. If columns need different formats (e.g. price with 2 decimals, volume abbreviated by 万), just create multiple instances.

Configuration Options

createNumberCell accepts a configuration object CreateNumberCellOptions (identical to FormatNumberOptions):

PropertyTypeDefaultDescription
decimalsnumber-Number of decimal places (rounded). Omit to leave decimals untouched
thousandsbooleantrueWhether to use a thousands separator
prefixstring''Prefix, e.g. ¥, $
suffixstring''Suffix, e.g. , shares
showSignbooleanfalseWhether positive numbers force a + sign (negatives always show -)
percentbooleanfalsePercentage mode: value ×100 with a trailing %. Mutually exclusive with abbr
abbr'cn' | 'en'-Unit abbreviation: cn=万/亿, en=K/M/B. Mutually exclusive with percent
abbrDecimalsnumber2Decimal places kept after abbreviation
placeholderstring'--'Placeholder for empty (null/undefined/'') or non-numeric values

Unit Abbreviation

abbr scales the value by magnitude and appends a unit:

  • abbr: 'cn': ≥ 100M shows as 亿, ≥ 10K shows as (e.g. 123451.23万, 1234567891.23亿)
  • abbr: 'en': scales by K (thousand) / M (million) / B (billion) (e.g. 15001.50K, 25000002.50M)

The decimals after abbreviation are controlled by abbrDecimals (default 2).

formatNumber

The formatting logic is provided by the pure function formatNumber(value, options), which is also exported. You can reuse it outside cells (e.g. footer totals, tooltips):

ts
import { formatNumber } from 'stk-table-solid';

formatNumber(1234567.891, { decimals: 2 }); // '1,234,567.89'
formatNumber(0.0523, { percent: true, decimals: 2, showSign: true }); // '+5.23%'

Released under the MIT License