diff --git a/src/common/utils/format.ts b/src/common/utils/format.ts index 32cb2ccba..3bd41e070 100644 --- a/src/common/utils/format.ts +++ b/src/common/utils/format.ts @@ -142,6 +142,19 @@ export function formatThousands(value: string | number, sign: string): string { return vl.replace(/(\d)(?=(\d{3})+$)/g, ($1) => `${$1}${sign}`) } +const subscriptNumbers: Record = { + 0: '₀', + 1: '₁', + 2: '₂', + 3: '₃', + 4: '₄', + 5: '₅', + 6: '₆', + 7: '₇', + 8: '₈', + 9: '₉' +} + export function formatFoldDecimal(value: string | number, threshold: number): string { const vl = `${value}` const reg = new RegExp('\\.0{' + threshold + ',}[1-9][0-9]*$') @@ -151,8 +164,8 @@ export function formatFoldDecimal(value: string | number, threshold: number): st const v = result[lastIndex] const match = /0*/.exec(v) if (isValid(match)) { - const count = match[0].length - result[lastIndex] = v.replace(/0*/, `0{${count}}`) + const count = `${match[0].length}` + result[lastIndex] = v.replace(/0*/, `0${count.replace(/\d/g, ($1) => subscriptNumbers[$1] ?? '')}`) return result.join('.') } }