This commit is contained in:
hosseintaromi 2025-09-26 12:17:59 +03:30
commit aec7db2c19
1 changed files with 7 additions and 4 deletions

View File

@ -86,13 +86,16 @@ export const createOptionalNumberTransform = () => {
export const formatWithThousands = (value: string | number): string => { export const formatWithThousands = (value: string | number): string => {
if (value === null || value === undefined) return ""; if (value === null || value === undefined) return "";
const str = persianToEnglish(value.toString()); const raw = persianToEnglish(value.toString());
if (str === "") return ""; if (raw === "") return "";
const parts = str.replace(/[^\d.]/g, "").split("."); const hasTrailingDot = /\.$/.test(raw);
const sanitized = raw.replace(/[^\d.]/g, "");
const parts = sanitized.split(".");
const integerPart = parts[0]; const integerPart = parts[0];
const decimalPart = parts.length > 1 ? parts[1] : ""; const decimalPart = parts.length > 1 ? parts[1] : "";
const withCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ","); const withCommas = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return decimalPart ? `${withCommas}.${decimalPart}` : withCommas; if (decimalPart) return `${withCommas}.${decimalPart}`;
return hasTrailingDot ? `${withCommas}.` : withCommas;
}; };
export const parseFormattedNumber = (value: any): number | undefined => { export const parseFormattedNumber = (value: any): number | undefined => {