useMoney
The useMoney
hook takes a MoneyV2 object and returns a
default-formatted string of the amount with the correct currency indicator, along with some of the parts provided by
Intl.NumberFormat.
Example code
Anchor link to section titled "Example code"
Return value
Anchor link to section titled "Return value"This hook returns an object with the following keys:
Key | Description |
---|---|
localizedString |
A string returned by new Intl.NumberFormat for the amount and currency code, using the locale value from the ShopifyProvider component. |
currencyCode |
The currency code from the MoneyV2 object. |
currencyName |
The name for the currency code, returned by Intl.NumberFormat . |
currencySymbol |
The currency symbol returned by Intl.NumberFormat . |
currencyNarrowSymbol |
The currency narrow symbol returned by Intl.NumberFormat . |
amount |
The localized amount, without any currency symbols or non-number types from the Intl.NumberFormat.formatToParts parts. |
parts |
All parts returned by Intl.NumberFormat.formatToParts . |
original |
The original MoneyV2 object passed as an argument. |
withoutTrailingZeros |
A string with trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains. For example, $640.00 turns into $640 . $640.42 turns into $640.42 . |
withoutTrailingZerosAndCurrency |
A string without currency and without trailing zeros removed from the fractional part, if any exist. If there are no trailing zeros, then the fractional part remains. For example, $640.00 turns into 640 . $640.42 turns into 640.42 . |