Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(formatters): Fixes a bug throwing an errror when setting maxPreci…
Browse files Browse the repository at this point in the history
…sion lower than 0 and the input higher that 1
  • Loading branch information
rowa-audil authored and ffriedl89 committed Jul 28, 2020
1 parent 4e952e3 commit 9c7c728
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ describe('FormatterUtil', () => {
maxPrecision: -1,
output: '< 1',
},
{
input: 1.123456789,
maxPrecision: -1,
output: '1',
},
{
input: 0.123456789,
output: '0.123',
Expand Down Expand Up @@ -262,7 +267,7 @@ describe('FormatterUtil', () => {
output: '-0.001',
},
].forEach((testCase: TestCase) => {
it(`should return ${testCase.input} with max precision`, () => {
it(`should return ${testCase.output} with input ${testCase.output} and max precision set to ${testCase.maxPrecision}`, () => {
expect(
adjustNumber(
testCase.input,
Expand Down
2 changes: 1 addition & 1 deletion libs/barista-components/formatters/src/number-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function adjustPrecision(value: number, maxPrecision?: number): string {
} else if (calcValue < 100) {
digits = 1;
}
return formatNumber(value, 'en-US', `0.0-${digits}`);
return formatNumber(value, 'en-US', `0.0-${digits < 0 ? 0 : digits}`);
}

function abbreviateNumber(sourceValue: number): string {
Expand Down

0 comments on commit 9c7c728

Please sign in to comment.