add suffix after percentage

This commit is contained in:
Nate Kelley 2025-09-15 16:01:26 -06:00
parent df138531f3
commit 0959403b47
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 19 additions and 1 deletions

View File

@ -358,4 +358,22 @@ describe('formatLabel', () => {
).toBe('null');
});
});
describe('percent formatter', () => {
it('should format percentages', () => {
expect(formatLabel(0.1234, { columnType: 'number', style: 'percent' })).toBe('0.12%');
});
it('should format percentages with custom format', () => {
expect(
formatLabel(0.1234, { columnType: 'number', style: 'percent', dateFormat: 'YYYY-MM-DD' })
).toBe('0.12%');
});
it('should put suffix after the percentage', () => {
expect(formatLabel(0.1234, { columnType: 'number', style: 'percent', suffix: ' WOW!' })).toBe(
'0.12% WOW!'
);
});
});
});

View File

@ -157,9 +157,9 @@ const prefixSuffixHandler = (
if (replaceMissingDataWith === null && !text) return String(text);
let result = String(text);
if (style === 'percent' && suffix !== '%') result = `${result}%`;
if (prefix) result = prefix + result;
if (suffix) result = result + suffix;
if (style === 'percent' && suffix !== '%') result = `${result}%`;
return result;
};