Files
discourse-subscriptions/assets/javascripts/discourse/helpers/format-currency.js
T
Blake Erickson 41c443ab23 FIX: Decimal point truncation (#223)
Amounts like $45.80 were being displayed as $45.8. Which doesn't look
correct for currency.

Bug Report: https://meta.discourse.org/t/316007
2024-07-19 07:18:28 -06:00

37 lines
737 B
JavaScript

import { helper } from "@ember/component/helper";
export function formatCurrency([currency, amount]) {
let currencySign;
switch (currency.toUpperCase()) {
case "EUR":
currencySign = "€";
break;
case "GBP":
currencySign = "£";
break;
case "INR":
currencySign = "₹";
break;
case "BRL":
currencySign = "R$";
break;
case "DKK":
currencySign = "DKK";
break;
case "SGD":
currencySign = "S$";
break;
case "ZAR":
currencySign = "R";
break;
default:
currencySign = "$";
}
let formattedAmount = parseFloat(amount).toFixed(2);
return currencySign + formattedAmount;
}
export default helper(formatCurrency);