multi-currency support in roi calculator
This commit is contained in:
parent
adc3a6b905
commit
5cc6b779c5
7 changed files with 231 additions and 45 deletions
|
|
@ -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)}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue