multi-currency support in roi calculator

This commit is contained in:
Tobias Brunner 2025-07-23 14:50:53 +02:00
parent adc3a6b905
commit 5cc6b779c5
Signed by: tobru
SSH key fingerprint: SHA256:kOXg1R6c11XW3/Pt9dbLdQvOJGFAy+B2K6v6PtRWBGQ
7 changed files with 231 additions and 45 deletions

View file

@ -203,43 +203,61 @@ class UIManager {
}
}
formatCurrency(amount) {
formatCurrency(amount, currency = null) {
try {
// Get current currency if not provided
if (!currency) {
const currencyElement = document.getElementById('currency');
currency = currencyElement ? currencyElement.value : 'CHF';
}
// Determine locale based on currency
const locale = currency === 'EUR' ? 'de-DE' : 'de-CH';
// Use compact notation for large numbers in metric cards
if (amount >= 1000000) {
return new Intl.NumberFormat('de-CH', {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: 'CHF',
currency: currency,
notation: 'compact',
minimumFractionDigits: 0,
maximumFractionDigits: 1
}).format(amount);
} else {
return new Intl.NumberFormat('de-CH', {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: 'CHF',
currency: currency,
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(amount);
}
} catch (error) {
console.error('Error formatting currency:', error);
return `CHF ${amount.toFixed(0)}`;
return `${currency || 'CHF'} ${amount.toFixed(0)}`;
}
}
formatCurrencyDetailed(amount) {
formatCurrencyDetailed(amount, currency = null) {
try {
// Get current currency if not provided
if (!currency) {
const currencyElement = document.getElementById('currency');
currency = currencyElement ? currencyElement.value : 'CHF';
}
// Determine locale based on currency
const locale = currency === 'EUR' ? 'de-DE' : 'de-CH';
// Use full formatting for detailed views (tables, exports)
return new Intl.NumberFormat('de-CH', {
return new Intl.NumberFormat(locale, {
style: 'currency',
currency: 'CHF',
currency: currency,
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(amount);
} catch (error) {
console.error('Error formatting detailed currency:', error);
return `CHF ${amount.toFixed(0)}`;
return `${currency || 'CHF'} ${amount.toFixed(0)}`;
}
}