19 lines
497 B
TypeScript
19 lines
497 B
TypeScript
import { Currency } from "@/shared/types";
|
|
import { symbolByCurrency } from "../constants/currency";
|
|
|
|
const addCurrency = (price: number | string, currency: Currency) => {
|
|
const symbol = symbolByCurrency[currency];
|
|
if ([Currency.EUR].includes(currency)) {
|
|
return `${price} ${symbol}`;
|
|
}
|
|
return `${symbol}${price}`;
|
|
};
|
|
|
|
export const getFormattedPrice = (
|
|
price: number,
|
|
currency: Currency,
|
|
precision = 2
|
|
) => {
|
|
return addCurrency((price / 100).toFixed(precision), currency);
|
|
};
|