In the response body of a call to https://*.myshopify.com/admin/orders.json, the JSON contains a number of string fields which represent monetary values. These include "total_price", "subtotal_price", "total_tax", "total_discounts", "total_line_items_price", "total_price_usd", "price" and "total_discount". In our test orders, we are seeing them come back with two decimal places ("345.20"), but I can't see anything in the documentation at https://help.shopify.com/api/reference/order to confirm that this will always be the case.
Is the format of these fields firmly documented anywhere so I know how to parse them reliably?
Hi @SerresPion ,
For currencies that use the cents system (e.g. USD, CAD, EUR, GBP) I can confirm that you will always see two decimal points in the string fields that represent monetary value. So an order that had a cost of $5 USD in the orders.json object would show as `total_price: "5.00"`
However this will not be the case for all currencies in the world. For example, if the Shopify store operates on the currency that of the Japanese Yen (JPY) as their shop currency. With this currency there is no (common place) concept of having decimals or denominations less than 1 yen. So in this case, the orders.json object would show something like `total_price: "11033"` instead.
Hassain | Developer Support Specialist @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution
Thanks @hassain for your answer.
Can I kindly ask you why money fields are typed as strings rather than as floats to begin with? No doubt there's a good reason behind that design choice but I'm most curious about it.