Sprint 4 — Etapa 7B completada.
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
Some checks failed
/ Deploy to Cloudflare Pages (push) Has been cancelled
This commit is contained in:
@@ -7,6 +7,23 @@ export function formatCurrency(amount: number, currency = 'USD'): string {
|
||||
}).format(amount)
|
||||
}
|
||||
|
||||
// Precisión dinámica para costo/hora de recursos: evita que valores chicos
|
||||
// (ej. licencias cloud a $0.037/h) se redondeen a $0.04 perdiendo la magnitud real.
|
||||
export function formatCostPerHour(value: number, currency = 'USD'): string {
|
||||
const symbol = currency === 'USD' ? '$' : currency
|
||||
if (value === 0) return `${symbol}0`
|
||||
|
||||
let decimals: number
|
||||
if (value >= 100) decimals = 0
|
||||
else if (value >= 10) decimals = 1
|
||||
else if (value >= 1) decimals = 2
|
||||
else if (value >= 0.1) decimals = 3
|
||||
else decimals = 4
|
||||
|
||||
// parseFloat recorta ceros sobrantes: toFixed(4) de 0.037 da "0.0370", queremos "0.037"
|
||||
return `${symbol}${parseFloat(value.toFixed(decimals))}`
|
||||
}
|
||||
|
||||
export function formatNumber(n: number, decimals = 1): string {
|
||||
return new Intl.NumberFormat('es-PY', {
|
||||
minimumFractionDigits: decimals,
|
||||
|
||||
Reference in New Issue
Block a user