mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-24 01:30:21 +00:00
40 lines
937 B
JavaScript
40 lines
937 B
JavaScript
function formateaMoneda(valor, digits = 2, locale = 'es-ES', currency = 'EUR') {
|
|
try {
|
|
return new Intl.NumberFormat(locale, { style: 'currency', currency, minimumFractionDigits: digits, useGrouping: true }).format(valor);
|
|
} catch {
|
|
return valor;
|
|
}
|
|
}
|
|
export { formateaMoneda };
|
|
|
|
|
|
function formateaNumero({
|
|
valor,
|
|
digits = 2,
|
|
style = 'decimal',
|
|
locale = 'es-ES',
|
|
currency = 'EUR'
|
|
}) {
|
|
const n = Number(valor);
|
|
if (!Number.isFinite(n)) return valor;
|
|
|
|
const opts = {
|
|
useGrouping: true,
|
|
minimumFractionDigits: digits,
|
|
maximumFractionDigits: digits,
|
|
};
|
|
|
|
if (style === 'currency') {
|
|
opts.style = 'currency';
|
|
opts.currency = currency;
|
|
}
|
|
|
|
return new Intl.NumberFormat(locale, opts).format(n);
|
|
}
|
|
export { formateaNumero };
|
|
|
|
|
|
function isNumber(value) {
|
|
return !isNaN(Number(value)) && value.trim() !== '';
|
|
}
|
|
export { isNumber }; |