fix: comma input & i18n
This commit is contained in:
parent
fb98ba3d32
commit
263a4fcedc
4 changed files with 13 additions and 8 deletions
|
|
@ -417,12 +417,17 @@ export async function waitAll<T extends Promise<any>[]>(arr: T) {
|
|||
}
|
||||
|
||||
export function commaInput(text: string): string {
|
||||
console.log(text);
|
||||
if (typeof text !== 'string') return '0';
|
||||
if (!text) return '0';
|
||||
const num = text.replace(/,/gi, '');
|
||||
const numF = num.split(/(?=(?:\d{3})+$)/).join(',');
|
||||
|
||||
return numF;
|
||||
const num = Number(text.replace(/,/gi, ''));
|
||||
|
||||
const parts = num.toString().split('.');
|
||||
const integerPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
const decimalPart = parts[1] || '';
|
||||
|
||||
return integerPart + (decimalPart ? `.${decimalPart}` : '');
|
||||
}
|
||||
|
||||
export default useUtilsStore;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue