fix: comma input behavior

This commit is contained in:
puriphatt 2024-12-25 15:47:25 +07:00
parent 61501dba8d
commit 889d4afbf5
6 changed files with 113 additions and 50 deletions

View file

@ -461,6 +461,7 @@ export function commaInput(
const integerPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
const decimalPart = parts[1]?.slice(0, 2) || (type === 'number' && '00');
if (integerPart === 'NaN') return '0';
return integerPart + (decimalPart ? `.${decimalPart}` : '');
}
@ -491,6 +492,12 @@ export function calculateDaysUntilExpire(expireDate: Date): number {
return diffInDays;
}
export function formatNumberWithCommas(value: string) {
const [integer, decimal] = value.split('.');
const integerWithCommas = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return decimal ? `${integerWithCommas}.${decimal}` : integerWithCommas;
}
export function createDataRefBase<T>(
defaultPage = 1,
defaultPageMax = 1,