mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-28 14:48:50 +00:00
terminado
This commit is contained in:
@ -1,26 +1,40 @@
|
||||
function formateaMoneda(valor) {
|
||||
function formateaMoneda(valor, digits = 2, locale = 'es-ES', currency = 'EUR') {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR' }).format(valor);
|
||||
return new Intl.NumberFormat(locale, { style: 'currency', currency, minimumFractionDigits: digits, useGrouping: true }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
export { formateaMoneda };
|
||||
|
||||
function formateaMoneda4Decimales(valor) {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR', minimumFractionDigits: 4 }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
}
|
||||
}
|
||||
export { formateaMoneda4Decimales };
|
||||
|
||||
function formateaMoneda6Decimales(valor) {
|
||||
try {
|
||||
return new Intl.NumberFormat('es-ES', { style: 'currency', currency: 'EUR', minimumFractionDigits: 6 }).format(valor);
|
||||
} catch {
|
||||
return valor;
|
||||
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 { formateaMoneda6Decimales };
|
||||
export { formateaNumero };
|
||||
|
||||
|
||||
function isNumber(value) {
|
||||
return !isNaN(Number(value)) && value.trim() !== '';
|
||||
}
|
||||
export { isNumber };
|
||||
Reference in New Issue
Block a user