You've already forked tf2wikipricing
20 lines
633 B
TypeScript
20 lines
633 B
TypeScript
import { $T } from './localization'
|
|
|
|
function toFixed(num: number, fixed: number) {
|
|
const re = new RegExp('^-?\\d+(?:\.\\d{0,' + (fixed || -1) + '})?');
|
|
return num.toString().match(re)[0];
|
|
}
|
|
|
|
export function formatPrice(keys: number, metal: number, keyPrice: number, locale: string = 'en') {
|
|
const formattedKeys = +(keys + (metal / keyPrice)).toFixed(2)
|
|
|
|
let output: string = ''
|
|
if(keys > 0) {
|
|
output += (formattedKeys == 1.0 ? $T("%@ key") : $T("%@ keys")).replace('%@', formattedKeys.toLocaleString(locale))
|
|
} else {
|
|
output += $T("%@ ref").replace('%@', (+toFixed(metal, 2)).toLocaleString(locale))
|
|
}
|
|
|
|
return output;
|
|
}
|