Files
compras/resources/js/lib/import-estimate-money.ts
T
nala e709d900d1
tests / ci (push) Waiting to run
commit compras 2711
2026-11-27 13:49:31 +02:00

11 lines
484 B
TypeScript

export const estimateMoney = (value: number | null) => {
if (value === null) return '';
const digits = String(value).padStart(3, '0');
return `${digits.slice(0, -2)}.${digits.slice(-2)}`;
};
export const estimateMinor = (value: string): number | string => {
if (!/^\d{1,13}(?:[.,]\d{1,2})?$/.test(value)) return value;
const [whole, fraction = ''] = value.replace(',', '.').split('.');
return Number(BigInt(whole) * 100n + BigInt(fraction.padEnd(2, '0')));
};