Money and currency

Tips for using currency and money values in your scripts.

International pricing and multi-currency aren't supported

Your store can't use international pricing or multi-currency with Shopify Scripts. All money values use the customer's currency (also referred to as the presentment currency). Because we don't support international or multi-currency, the presentment currency is the same as the store currency.

Use configurations to provide money values

Do not hard code money amounts into your scripts. Use configurations instead to provide the monetary amounts to your script. Because configuration values are saved as strings, you need to:

  1. Transform the string into a subunits value
  2. Create a Money object with this transformed subunits value. The currency needs to be the same as the store currency.

For example:

Order of operations for Money objects

The Money objects override common binary operations like multiplication, division, and addition. You can also apply these binary operations with a Money object and a numeric value, such as float. When you do this, the order of operations matters. The order matters because the binary operation is just a plain method call in the Money class that expects a numeric value as a parameter. As a result, Money * 4 works but 4 * Money doesn't.

Use SafeParseInt instead of ParseInt

AssemblyScript has some special cases when parsing strings into numeric values. For example, I32.parseInt("bad") returns 0, but F64.parseInt("bad") returns NaN. F64 is the most flexible numeric type in AssemblyScript and you're encouraged to use it.

To avoid the complexity of parseInt, use the safeParseInt function. safeParseInt throws an exception when the passed string is not a number. safeParseInt is defined in the Scripts library, so it's available for use in all scripts.