Skip to content

Commit 514a004

Browse files
authored
Merge pull request #53 from techniq/fix-metric-decimal
fix(format): Do not truncate decimal values when using `metric` preset (ex. 0.5)
2 parents 2b6556a + 955e07b commit 514a004

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

.changeset/real-spoons-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@layerstack/utils': patch
3+
---
4+
5+
fix(format): Do not truncate decimal values when using `metric` preset (ex. 0.5)

packages/utils/src/lib/number.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,19 @@ describe('formatNumber()', () => {
275275
});
276276
expect(actual).equal('200 m²');
277277
});
278+
279+
it('0.5 (decimal)', () => {
280+
const actual = formatNumber(0.5, 'metric');
281+
expect(actual).equal('0.5');
282+
});
283+
284+
it('0.05 (decimal)', () => {
285+
const actual = formatNumber(0.05, 'metric');
286+
expect(actual).equal('0.05');
287+
});
288+
289+
it('0.005 (decimal)', () => {
290+
const actual = formatNumber(0.005, 'metric');
291+
expect(actual).equal('0.01');
292+
});
278293
});

packages/utils/src/lib/number.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ export function formatNumberWithLocale(
9898
style: 'decimal',
9999
notation: 'compact',
100100
minimumFractionDigits: 0,
101-
maximumFractionDigits: 0,
102101
}),
103102

104103
// Let's overwrite for style=integer

0 commit comments

Comments
 (0)