Commit 360409e6 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'locale-number-formatting' into 'master'

Support number formatting from user settings

See merge request gitlab-org/gitlab!52002
parents 596c61e2 b9ca7d93
...@@ -20,8 +20,9 @@ function formatNumber( ...@@ -20,8 +20,9 @@ function formatNumber(
return ''; return '';
} }
const locale = document.documentElement.lang || undefined;
const num = value * valueFactor; const num = value * valueFactor;
const formatted = num.toLocaleString(undefined, { const formatted = num.toLocaleString(locale, {
minimumFractionDigits: fractionDigits, minimumFractionDigits: fractionDigits,
maximumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits,
style, style,
......
...@@ -36,6 +36,27 @@ describe('unit_format/formatter_factory', () => { ...@@ -36,6 +36,27 @@ describe('unit_format/formatter_factory', () => {
expect(formatNumber(10 ** 7, undefined, 9)).toBe('1.00e+7'); expect(formatNumber(10 ** 7, undefined, 9)).toBe('1.00e+7');
expect(formatNumber(10 ** 7, undefined, 10)).toBe('10,000,000'); 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', () => { describe('suffixFormatter', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment