Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/createPartition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function createPartition (tokens?: RenderToken[]): Partition {
pattern: '',
int_max: 0,
frac_max: 0,
frac_min: 0,
man_p: '',
num_p: '',
num_min: 0,
Expand Down
1 change: 1 addition & 0 deletions lib/formatInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function info (partitions: Partition[], currencyId?: string): FormatInfo
isText: isText(partitions),
isPercent: isPercent(partitions),
maxDecimals: partPos.general ? 9 : frac_max,
minDecimals: partPos.general ? 0 : partPos.frac_min,
scale: partPos.scale ?? 1,
color: 0,
parentheses: 0,
Expand Down
1 change: 1 addition & 0 deletions lib/parseFormatSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ export function parseFormatSection (inputTokens: Token[]) {
}
part.int_min = min;
part.frac_max = fracPattern.length;
part.frac_min = countNonHash(fracPattern);

let num_pat = part.num_pattern.join('');
// let den_pat = part.den_pattern.join('');
Expand Down
3 changes: 3 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export type Partition = {
int_max: number,
den_max: number,
frac_max: number,
frac_min: number,
date_eval: boolean,
date_system: typeof EPOCH_1900 | typeof EPOCH_1317,
dec_fractions?: boolean;
Expand Down Expand Up @@ -188,6 +189,8 @@ export type FormatInfo = {
isPercent: boolean;
/** The maximum number of decimals this format will emit. */
maxDecimals: number;
/** The minimum number of decimal places this format will reserve. */
minDecimals: number;
/**
* 1 if the format uses color on the negative portion of the string, else
* a 0. This replicates Excel's `CELL("color")` functionality.
Expand Down
38 changes: 38 additions & 0 deletions test/info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const commonProps = {
isText: false,
isPercent: false,
maxDecimals: 0,
minDecimals: 0,
grouped: 0,
parentheses: 0,
color: 0,
Expand Down Expand Up @@ -42,6 +43,7 @@ test('getFormatInfo', () => {
isText: false,
isPercent: false,
maxDecimals: 0,
minDecimals: 0,
color: 0,
scale: 1,
parentheses: 0,
Expand All @@ -58,6 +60,7 @@ test('getFormatInfo', () => {
isText: false,
isPercent: false,
maxDecimals: 0,
minDecimals: 0,
scale: 1,
color: 0,
parentheses: 0,
Expand All @@ -73,6 +76,7 @@ test('getFormatInfo', () => {
isText: false,
isPercent: false,
maxDecimals: 0,
minDecimals: 0,
scale: 1,
color: 0,
parentheses: 0,
Expand Down Expand Up @@ -111,24 +115,49 @@ test('Numbers', () => {
});
assertInfo('0.0', {
type: 'number',
minDecimals: 1,
maxDecimals: 1,
code: 'F1',
level: 4
});
assertInfo('0.#', {
type: 'number',
minDecimals: 0,
maxDecimals: 1,
code: 'F1',
level: 4
});
assertInfo('0.00##', {
type: 'number',
minDecimals: 2,
maxDecimals: 4,
code: 'F4',
level: 4
});
assertInfo('0.0?', {
type: 'number',
minDecimals: 2,
maxDecimals: 2,
code: 'F2',
level: 4
});
assertInfo('0.000', {
type: 'number',
minDecimals: 3,
maxDecimals: 3,
code: 'F3',
level: 4
});
assertInfo('0.000000000000000', {
type: 'number',
minDecimals: 15,
maxDecimals: 15,
code: 'F15',
level: 4
});
assertInfo('0.0000000000000000', {
type: 'number',
minDecimals: 16,
maxDecimals: 16,
code: 'F15',
level: 4
Expand All @@ -143,13 +172,15 @@ test('Numbers', () => {
});
assertInfo('#,##0.00', {
type: 'grouped',
minDecimals: 2,
maxDecimals: 2,
code: ',2',
grouped: 1,
level: 10.2
});
assertInfo('(#,##0.00)', {
type: 'grouped',
minDecimals: 2,
maxDecimals: 2,
code: ',2()',
parentheses: 1,
Expand All @@ -159,13 +190,15 @@ test('Numbers', () => {

assertInfo('0.00,"K"', {
type: 'number',
minDecimals: 2,
maxDecimals: 2,
code: 'F2',
scale: 0.001,
level: 4
});
assertInfo('0.00,,"K"', {
type: 'number',
minDecimals: 2,
maxDecimals: 2,
code: 'F2',
scale: 0.000001,
Expand Down Expand Up @@ -264,13 +297,15 @@ test('Currency', () => {
assertInfo('#,##0.00 €', {
type: 'currency',
code: 'C2',
minDecimals: 2,
maxDecimals: 2,
grouped: 1,
level: 10.4
});
assertInfo('₿ 0.0000', {
type: 'currency',
code: 'C4',
minDecimals: 4,
maxDecimals: 4,
level: 10.4
});
Expand Down Expand Up @@ -307,6 +342,7 @@ test('Percentages', () => {
scale: 100,
code: 'P2-',
color: 1,
minDecimals: 2,
maxDecimals: 2,
level: 10.6
});
Expand All @@ -321,13 +357,15 @@ test('Scientific', () => {
assertInfo('0.00E+00', {
type: 'scientific',
code: 'S2',
minDecimals: 2,
maxDecimals: 2,
level: 6
});
assertInfo('0.0E+0;[red]0.0E+0', {
type: 'scientific',
code: 'S1-',
color: 1,
minDecimals: 1,
maxDecimals: 1,
level: 6
});
Expand Down