You've already forked tf2wikipricing
refactor: split currency and key/metal formatting into separate units
this simplifies functions and tests, and will make currency optional/variable later
This commit is contained in:
8
src/content/utils/currency.ts
Normal file
8
src/content/utils/currency.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { conversion_ref_usd } from '../config';
|
||||
|
||||
export function convertTF2PriceToUSD(keys: number, metal: number, keyPrice: number): number {
|
||||
const pureMetal = (keys * keyPrice) + metal;
|
||||
|
||||
// Round price up to nearest cent
|
||||
return Math.ceil(pureMetal * conversion_ref_usd * 100) / 100
|
||||
}
|
||||
@@ -7,7 +7,6 @@ function toFixed(num: number, fixed: number) {
|
||||
}
|
||||
|
||||
export function formatPrice(keys: number, metal: number, keyPrice: number, locale: string = 'en') {
|
||||
const pureMetal = (keys * keyPrice) + metal;
|
||||
const formattedKeys = +(keys + (metal / keyPrice)).toFixed(2)
|
||||
|
||||
var output: string = ''
|
||||
@@ -16,13 +15,6 @@ export function formatPrice(keys: number, metal: number, keyPrice: number, local
|
||||
} else {
|
||||
output += $T("%@ ref").replace('%@', (+toFixed(metal, 2)).toLocaleString(locale))
|
||||
}
|
||||
const currencyFormatter = new Intl.NumberFormat(locale, {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
|
||||
// Round price up to nearest cent
|
||||
const price = Math.ceil(pureMetal * conversion_ref_usd * 100) / 100
|
||||
output += ` (US$${currencyFormatter.format(price)})`
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user