Skip to main content
Skip to main content

formatAmount

This utility function can be used to compute the price of an amount for a region and retrieve the formatted amount. For example, $20.00.

The main difference between this utility function and formatVariantPrice is that you don’t need to pass a complete variant object. This can be used with any number.

Example

import React from "react"
import { formatVariantPrice } from "medusa-react"
import { Product, ProductVariant } from "@medusajs/medusa"

const Products = () => {
// ...
return (
<ul>
{products?.map((product: Product) => (
<li key={product.id}>
{product.title}
<ul>
{product.variants.map((variant: ProductVariant) => (
<li key={variant.id}>
{formatVariantPrice({
variant,
region, // should be retrieved earlier
})}
</li>
))}
</ul>
</li>
))}
</ul>
)
}

Parameters

param0FormatAmountParamsRequired
Options to format the amount.

Returns

stringstringRequired
The formatted price.
Was this section helpful?