import { MoneyDTO } from "@erp/core"; import { MoneyValue } from "@repo/rdx-ddd"; export type FormatMoneyOptions = { locale: string; hideZeros?: boolean; newScale?: number; }; export function formatMoneyDTO( amount: MoneyDTO, { locale, hideZeros = false, newScale = 2 }: FormatMoneyOptions ) { if (hideZeros && (amount.value === "0" || amount.value === "")) { return null; } const money = MoneyValue.create({ value: Number(amount.value), currency_code: amount.currency_code, scale: Number(amount.scale), }).data; return money.convertScale(newScale).format(locale); }