The product/variant price, usdPrice, currencyCode, quantity, and uom fields.
The user's currency and currencyRate; defaults to USD at rate 1 when undefined.
A localized full-precision "{price}/{unit}" string, or "" when unavailable.
formatUnitPriceExact({ price: 5, usdPrice: 5, currencyCode: "USD", quantity: 1, uom: "kg" }, undefined);
// => "$0.005/g"
formatUnitPriceExact({ price: 40, usdPrice: 40, currencyCode: "USD", quantity: 500, uom: "g" }, { currency: "EUR", currencyRate: 0.9 });
// => "€0.072/g"
export function formatUnitPriceExact(
product: UnitPriceFields,
userSettings: PriceSettings | undefined,
): string {
const resolved = resolveUnitPrice(product, userSettings);
if (!resolved) return '';
const { currency, perUnit, unitLabel } = resolved;
return `${formatWithSymbol(currency, perUnit, unitPriceExactFractionDigits)}/${unitLabel}`;
}
Formats a product's price per base unit at full precision — up to four decimal places, with no sub-cent collapse — for use as the hover tooltip behind the rounded formatUnitPrice display, so a value shown as
"<$0.01/g"or"$0.07/g"reveals its actual"$0.0035/g"/"$0.072/g"on hover. Uses the same resolved amount as the display formatter (seeresolveUnitPrice). Returns""when there's no price or the quantity/unit can't be converted.