Impove Intl formatting (#5372)
* Improve Intl formatting * Additional fixes * Fixed formatters were not updated on locale change * Fixed formatNumber was not updated on locale change * Additional formatting and fixes after merge * Run prepr:frontend * Remove `'` in icon map * Run `pnpm install` * fix: lint + import * Additional fixes --------- Co-authored-by: Calum H. <calum@modrinth.com> Co-authored-by: Calum H. (IMB11) <contact@cal.engineer>
This commit is contained in:
@@ -60,29 +60,6 @@ export const getCurrency = (userCountry) => {
|
||||
return countryCurrency[userCountry] ?? 'USD'
|
||||
}
|
||||
|
||||
export const formatPrice = (locale, price, currency, trimZeros = false) => {
|
||||
let formatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
})
|
||||
|
||||
const maxDigits = formatter.resolvedOptions().maximumFractionDigits
|
||||
const convertedPrice = price / Math.pow(10, maxDigits)
|
||||
|
||||
let minimumFractionDigits = maxDigits
|
||||
|
||||
if (trimZeros && Number.isInteger(convertedPrice)) {
|
||||
minimumFractionDigits = 0
|
||||
}
|
||||
|
||||
formatter = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency,
|
||||
minimumFractionDigits,
|
||||
})
|
||||
return formatter.format(convertedPrice)
|
||||
}
|
||||
|
||||
export const calculateSavings = (monthlyPlan, plan, months = 12) => {
|
||||
const monthlyAnnualized = monthlyPlan * months
|
||||
|
||||
|
||||
Reference in New Issue
Block a user