0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Fixed offers index pricing decimals (#19125)

no issue

- changes the price tags on the offer cards to two decimal places.
This commit is contained in:
Ronald Langeveld 2023-11-24 14:06:19 +02:00 committed by GitHub
parent 41ee387af2
commit 62b71fb4c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,7 +34,10 @@ export const getOfferDiscount = (type: string, amount: number, cadence: string,
let discountOffer = '';
const originalPrice = cadence === 'month' ? tier?.monthly_price ?? 0 : tier?.yearly_price ?? 0;
let updatedPrice = originalPrice;
let originalPriceWithCurrency = getSymbol(currency) + numberWithCommas(currencyToDecimal(originalPrice));
const formatToTwoDecimals = (num: number): number => parseFloat(num.toFixed(2));
let originalPriceWithCurrency = getSymbol(currency) + numberWithCommas(formatToTwoDecimals(currencyToDecimal(originalPrice)));
switch (type) {
case 'percent':
@ -44,7 +47,7 @@ export const getOfferDiscount = (type: string, amount: number, cadence: string,
break;
case 'fixed':
discountColor = 'text-blue';
discountOffer = numberWithCommas(currencyToDecimal(amount)) + ' ' + currency + ' off';
discountOffer = numberWithCommas(formatToTwoDecimals(currencyToDecimal(amount))) + ' ' + currency + ' off';
updatedPrice = originalPrice - amount;
break;
case 'trial':
@ -56,7 +59,7 @@ export const getOfferDiscount = (type: string, amount: number, cadence: string,
break;
};
const updatedPriceWithCurrency = getSymbol(currency) + numberWithCommas(currencyToDecimal(updatedPrice));
const updatedPriceWithCurrency = getSymbol(currency) + numberWithCommas(formatToTwoDecimals(currencyToDecimal(updatedPrice)));
return {
discountColor,