11 lines
484 B
TypeScript
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')));
|
|
};
|