diff --git a/src/utils/numberUtils.ts b/src/utils/numberUtils.ts index 163d0dc..fa72cad 100644 --- a/src/utils/numberUtils.ts +++ b/src/utils/numberUtils.ts @@ -86,13 +86,16 @@ export const createOptionalNumberTransform = () => { export const formatWithThousands = (value: string | number): string => { if (value === null || value === undefined) return ""; - const str = persianToEnglish(value.toString()); - if (str === "") return ""; - const parts = str.replace(/[^\d.]/g, "").split("."); + const raw = persianToEnglish(value.toString()); + if (raw === "") return ""; + const hasTrailingDot = /\.$/.test(raw); + const sanitized = raw.replace(/[^\d.]/g, ""); + const parts = sanitized.split("."); const integerPart = parts[0]; const decimalPart = parts.length > 1 ? parts[1] : ""; 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 => {