Cracking the Code: How to Fix Shopify's Tricky Discount Rounding for Unit-Priced Products

Hey fellow store owners! Ever found yourself scratching your head over weird discount calculations on your Shopify store, especially if you sell items by unit of measurement like centimeters or grams? You’re definitely not alone. I recently followed a fascinating discussion in the Shopify community that perfectly illustrates this common headache, and I want to share the insights with you.

Maria, who runs a fabric store, brought up a classic scenario: she sells fabric at €0.15 per centimeter. When a customer applies a 10% discount code, the math goes a bit wonky. Instead of getting the correct discount, Shopify was applying a much smaller amount. For 80cm of fabric, which totals €13.60, a 10% discount should be €1.36. But Maria was seeing only €0.80 taken off! Talk about frustrating for both her and her customers.

Understanding Shopify's Discount Math

So, what’s happening here? The core of the problem lies in how Shopify’s native discount types handle rounding, especially when dealing with very low unit prices. As community expert Ploqo clarified, there are two main types of percentage discounts in Shopify:

  • Amount off product: This type calculates the discount for one unit, rounds that value to the nearest cent, and then multiplies it by the quantity. In Maria's case, €0.15 × 10% = €0.015. Shopify rounds this down to €0.01 per unit. So, for 80cm, the discount becomes 80 × €0.01 = €0.80. That's the culprit!
  • Amount off order: This type calculates the discount on the line subtotal (price × quantity) and rounds only once. This is what we want for accurate calculations. For Maria, 80cm × €0.15 = €13.60. A 10% discount on €13.60 is exactly €1.36. Perfect!

The catch? Native "Amount off order" discounts apply to all products in the cart, which isn't ideal if you only want to discount specific collections or items, as Maria needed.

Here’s a visual from Ploqo showing the difference:

Solution 1: The Targeted Order Discount App (Cart Marshal)

For many store owners, a third-party app is the quickest and most accessible solution. Josh-FiveAcreCode, the developer of Cart Marshal, jumped into the discussion with a perfect fit. His app allows you to create an "Order Discount" that calculates against the eligible subtotal (solving the rounding problem) AND lets you restrict it to specific products, collections, or tags (solving the "too broad" problem of native order discounts).

Maria initially struggled, setting it up as a "Product Discount" in Cart Marshal, which still led to per-unit rounding. But once Josh guided her to switch to an "Order Discount" type within the app, the calculation was spot on! The app even offers a legitimately free tier for a single rule, which is great for this specific use case.

How to Set Up a Targeted Order Discount with Cart Marshal:

  1. Install the Cart Marshal app from the Shopify App Store.
  2. In the Cart Marshal admin, choose to create an Order Discount rule.
  3. Set the discount type to Discount code (e.g., WELCOME10).
  4. Enter your desired discount code.
  5. Set the discount to your desired percentage (e.g., 10%).
  6. Crucially, restrict the eligible products using your collection or product criteria. This ensures the discount only applies where you want it.
  7. Publish the rule.

This approach gives you the best of both worlds: accurate subtotal-level discounting with the flexibility of targeting specific items via a discount code.

Solution 2: Custom Shopify Functions for Developers

If you're a developer or have access to one, and prefer a custom-coded solution, Ahsandoesntcare pointed to Shopify Functions as the standard approach. This involves building a custom app using the Product Discount Function API.

Key steps for a Custom Shopify Function:

  • Use the Shopify CLI with the Product Discount Function API template to create your app.
  • In your function logic, filter cart lines by product tags or collection IDs, just like you would with an app.
  • Instead of applying a percentage target directly, calculate the exact percentage discount amount based on the line_price (which is quantity * price).
  • Return that calculated amount as a fixed amount discount targeted to the specific line item.

This method ensures precision on fractional pricing and integrates seamlessly with standard promo codes in your Shopify admin.

Addressing the Display Glitch: €16/m vs. €15.30/m

Even after Maria got her discount calculations correct with Cart Marshal, a new display issue popped up. Her product was €1.70 per 10cm (or €0.17/cm). With a 10% discount, the price should be €1.53 per 10cm (€0.153/cm). However, Shopify's native unit-price display was showing €1.60 per 10cm (€0.16/cm)!

Josh explained that this is due to Shopify's default unit-price value rounding to cent precision. So, €0.153/cm gets rounded up to €0.16/cm for display purposes. While the actual total discount was correct, the displayed unit price was misleading for customers.

Here are Maria's screenshots showing the display error:

Fixing the Display: A Theme Code Adjustment

To fix this, you'd need a small Liquid/theme change. The idea is to adjust your theme's cart code (Maria's store uses Minimog) so that it calculates the effective discounted unit price from the final line total, rather than relying on Shopify’s rounded unit-price value. This usually means diving into files like cart-template.liquid or similar. If you're not comfortable with theme code, it's definitely worth reaching out to a developer or your theme's support for assistance.

This community discussion really highlights how important it is to understand the nuances of platform functionality, especially when it comes to pricing and discounts. Whether you choose an app like Cart Marshal or opt for a custom Shopify Function, ensuring your discounts are both calculated and displayed correctly is crucial for customer trust and a smooth shopping experience. And if you're thinking about starting your own Shopify store, these are the kinds of expert insights that can save you a lot of headaches down the line!

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases