Merge branch 'main' of https://github.com/mazane-front/backoffice
This commit is contained in:
commit
aec7db2c19
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue