Appearance
usePrice
Internally, usePrice
composable uses Intl.NumberFormat in order to format a price according to the right currency standard, for corresponding locale and symbol.
js
const { init, getFormattedPrice } = usePrice();
init({
currencyCode: 'EUR'
localeCode: 'de-DE' // value taken from browser's navigator.language variable if localeCode is not provided
})
const regularPrice = getFormattedPrice(49.95);
// regularPrice: '49,95 €'
Definition
Composable for getting formatted price
Basic usage
ts
const { init, getFormattedPrice } = usePrice();
Signature
ts
export function usePrice(): UsePriceReturn
Return type
See UsePriceReturn
ts
export type UsePriceReturn = {
/**
* Set init data: localeCode & currencyCode
*/
init(options: { localeCode: string | undefined; currencyCode: string }): void;
/**
* Format price i.e. (2) -> 2.00 $
*/
getFormattedPrice(value: number | string | undefined): string;
};
Methods
Name | Type | Description |
---|---|---|
init | void | Set init data: localeCode & currencyCode |
getFormattedPrice | string | Format price i.e. (2) -> 2.00 $ |