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 => {
|
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 => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue