15 lines
500 B
TypeScript
15 lines
500 B
TypeScript
import { Currency } from "@/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: number = 2) => {
|
|
return addCurrency((price / 100).toFixed(precision), currency);
|
|
}; |