Skip to content

Commit

Permalink
feat(statistic): add getFormatValue (#1660)
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 authored Nov 28, 2023
1 parent b194356 commit 2410c7b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions js/statistic/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ export const COLOR_MAP = {
orange: 'var(--td-warning-color)',
green: 'var(--td-success-color)',
};

export function getFormatValue(value:number | undefined | string, decimalPlaces:number, separator:string) {
const options = {
minimumFractionDigits: decimalPlaces ?? 0,
maximumFractionDigits: decimalPlaces ?? 20,
useGrouping: !!separator,
};
// replace的替换的方案仅能应对大部分地区
return value.toLocaleString(undefined, options).replace(/,|/g, separator);
}

0 comments on commit 2410c7b

Please sign in to comment.