Skip to content

Commit

Permalink
feat: add thousands format for numbers (#2337)
Browse files Browse the repository at this point in the history
Cherry-pick #2261

Co-authored-by: Steven Wu <[email protected]>
  • Loading branch information
vbabich and wusteven815 authored Jan 9, 2025
1 parent 674ab32 commit 8cebb63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class DecimalFormatContextMenu {
format: DecimalColumnFormatter.FORMAT_BASIS_POINTS,
group: DecimalFormatContextMenu.presetGroup,
},
{
format: DecimalColumnFormatter.FORMAT_THOUSANDS,
group: DecimalFormatContextMenu.presetGroup,
},
{
format: DecimalColumnFormatter.FORMAT_MILLIONS,
group: DecimalFormatContextMenu.presetGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class IntegerFormatContextMenu {
onCustomFormatChange: (value: IntegerColumnFormat | null) => void
): FormatContextMenuOption[] {
const formatItems = [
{
format: IntegerColumnFormatter.FORMAT_THOUSANDS,
group: IntegerFormatContextMenu.presetGroup,
},
{
format: IntegerColumnFormatter.FORMAT_MILLIONS,
group: IntegerFormatContextMenu.presetGroup,
Expand Down
6 changes: 6 additions & 0 deletions packages/jsapi-utils/src/formatters/DecimalColumnFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export class DecimalColumnFormatter extends TableColumnFormatter<number> {
10000
);

static FORMAT_THOUSANDS = DecimalColumnFormatter.makePresetFormat(
'Thousands',
'##0.000 k',
0.001
);

static FORMAT_MILLIONS = DecimalColumnFormatter.makePresetFormat(
'Millions',
'###,##0.000 mm',
Expand Down
6 changes: 6 additions & 0 deletions packages/jsapi-utils/src/formatters/IntegerColumnFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export class IntegerColumnFormatter extends TableColumnFormatter<number> {

static DEFAULT_FORMAT_STRING = '###,##0';

static FORMAT_THOUSANDS = IntegerColumnFormatter.makePresetFormat(
'Thousands',
'##0.000 k',
0.001
);

static FORMAT_MILLIONS = IntegerColumnFormatter.makePresetFormat(
'Millions',
'###,##0.000 mm',
Expand Down

0 comments on commit 8cebb63

Please sign in to comment.