Skip to content
Snippets Groups Projects
Commit b9ca7d93 authored by Miguel Rincon's avatar Miguel Rincon
Browse files

Support number formatting from user settings

This change checks the current locale in the document to select
which locale should be used when formatting numbers.
parent 458c0d35
No related branches found
No related tags found
1 merge request!52002Support number formatting from user settings
Pipeline #246439476 passed
......@@ -20,8 +20,9 @@ function formatNumber(
return '';
}
const locale = document.documentElement.lang || undefined;
const num = value * valueFactor;
const formatted = num.toLocaleString(undefined, {
const formatted = num.toLocaleString(locale, {
minimumFractionDigits: fractionDigits,
maximumFractionDigits: fractionDigits,
style,
......
......@@ -36,6 +36,27 @@ describe('unit_format/formatter_factory', () => {
expect(formatNumber(10 ** 7, undefined, 9)).toBe('1.00e+7');
expect(formatNumber(10 ** 7, undefined, 10)).toBe('10,000,000');
});
describe('formats with a different locale', () => {
let originalLang;
beforeAll(() => {
originalLang = document.documentElement.lang;
document.documentElement.lang = 'es';
});
afterAll(() => {
document.documentElement.lang = originalLang;
});
it('formats a using the correct thousands separator', () => {
expect(formatNumber(1000000)).toBe('1.000.000');
});
it('formats a using the correct decimal separator', () => {
expect(formatNumber(12.345)).toBe('12,345');
});
});
});
describe('suffixFormatter', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment