Variant price gets multiplied by 1,000

Variant price gets multiplied by 1,000

Kosmos_eSync_Te
Shopify Partner
21 0 0

We're running into an issue when attempting to modify variant prices with the Product Variant API where the provided price gets by 1,000. 

 

We've been able to replicate the issue consistently with different variant items when the price provided in the request is greater than 1 and contains 3 decimals. 

 

For example, providing a price value of 0.789 in the PUT request to the Product Variant API works as expected and causes the API to assign a price of $0.79.

 

However, if we provide a price of 3.789 this causes the Product Variant API to multiple the price by 1,000 and assign a price of $3,789.00 instead of $3.79. Is there anyway to prevent this?

 

 

 

Replies 3 (3)

Ben310
Globetrotter
632 93 147

Might be due to a misinterpretation of the decimal place by the API. When working with monetary values, use two decimal places to denote cents. You provided three decimal places, which could be the cause.

When you input a value like 3.789, the API could be treating this as "3789 cents", which equates to "$37.89" and when it gets multiplied by 100 (to avoid floating point issues), it outputs "$3789".

 

Input a price value with only two decimal places (e.g., 3.79) and see if the API handles it correctly.  Or input a price value greater than 1 with three decimal places (e.g., 3.789) and see if the resulting price in the Shopify system is a hundred times the expected value, not a thousand times. If this is the case, then...Bingo!

Kosmos_eSync_Te
Shopify Partner
21 0 0

Hi Ben,

 

In the provided example we saw the price got multiplied by 1,000 if the value is greater than 1 with 3 decimal places. For example, providing a price value of $3.789 results in the Product Variant API applying a price of $3,789.00.

 

We've been able to replicate this across different variant items and Shopify accounts when the price value provided to the Product Variant API is greater than 1 with 3 decimals. We have not been able to replicate the problem if there are more (or less) than 3 decimals, or if price value is less than 1.

 

If there's no way to prevent the issue on the Shopify side we'll need to look into solving this problem with code on our end.

 

 

Ben310
Globetrotter
632 93 147

Hey @Kosmos_eSync_Te 

 

Getting back to you now about the issue:

 

So it may be due to how the Shopify API interprets the number. If a value includes three decimal places, the API may be interpreting it as a value in cents instead of dollars for values larger than 1, i.e. it might interpret the third decimal place as a cent value, which would explain why you're seeing a multiplication by 1000.

So because the API behaves as expected with two decimal places, why not try adjusting the price value on your side to include only two decimal places before sending it to the Shopify API. You could round the value to two decimal places, either rounding down (floor) or up (ceil), or to the nearest whole number (round), depending on your pricing strategy. 

The following code will give you 3.79:

 

let price = 3.789;
price = Math.round(price * 100) / 100; // rounds to two decimal places

 

Have you contacted Shopify Support about this, and if yes, what did they say?