Files
nashel-frontend/src/shared/lib/formatPrice.ts
T

27 lines
883 B
TypeScript

/**
* Форматирует цену с разделением разрядов пробелом (русский стандарт).
* Пример: 400000 → "400 000 ₽"
*/
export function formatPrice(amount: number, type?: number | string): string {
if (type === 2 || type === "Negotiable") return "Договорная"
const formatted = amount.toLocaleString("ru-RU", {
maximumFractionDigits: 0,
useGrouping: true,
})
const suffix = (type === 1 || type === "Hourly") ? "/час" : ""
return `${formatted}${suffix}`
}
/**
* Форматирует число с разделением разрядов пробелом.
* Пример: 400000 → "400 000"
*/
export function formatNumber(amount: number): string {
return amount.toLocaleString("ru-RU", {
maximumFractionDigits: 0,
useGrouping: true,
})
}