Math.ceil((0.14 / (1 - 0.30)) * 100) returns 21 in JavaScript. With a landed cost of $0.14 and a 30% gross margin floor, $0.20 meets the floor exactly. The floating-point expression feeds 20.000000000000004 to Math.ceil, adding a cent to the minimum sell price. Once the CSV publishes that unit price, every unit in the order inherits the error.

A line sheet needs three explicit rules. Parse USD amounts into integer cents, round a minimum acceptable price up to the next cent, and round a minimum order quantity (MOQ) up to a whole case. Keep the rounded margin percentage for display and validate thresholds against the exact ratio. The TypeScript blocks below form one script. Paste them in order into wholesale.ts and run node wholesale.ts with Node.js 24.

Compute keystone MSRP and margin floors in cents

Read the CSV price cell as text. The parser below accepts non-negative USD amounts with up to two decimal places. Validate the currency before using it, and agree on how to allocate inbound freight, duty, and handling to the landed unit cost before pricing the item. Gross margin is (sell − cost) / sell. With keystone pricing, MSRP = 2 × boutique wholesale, so a boutique selling at MSRP earns a 50% product gross margin before its own costs. The brand's gross margin uses landed cost and the wholesale price for the buyer's tier.

import assert from 'node:assert/strict'; const BPS = 10_000n; function parseUsd(cell: string): bigint { const match = /^(0|[1-9][0-9]*)(?:\.([0-9]{1,2}))?$/.exec(cell.trim()); if (!match) throw new RangeError(`Invalid USD amount: ${cell}`); return BigInt(match[1]) * 100n + BigInt((match[2] ?? '').padEnd(2, '0')); } function ceilDiv(value: bigint, divisor: bigint): bigint { if (value < 0n || divisor <= 0n) throw new RangeError('Invalid ceiling division'); const quotient = value / divisor; return value % divisor === 0n ? quotient : quotient + 1n; } function keystoneMsrp(wholesaleCents: bigint): bigint { if (wholesaleCents <= 0n) throw new RangeError('Wholesale price must be positive'); return wholesaleCents * 2n; } function minimumSellPrice(cost: bigint, floorBps: bigint): bigint { if (cost <= 0n || floorBps < 0n || floorBps >= BPS) { throw new RangeError('Invalid landed cost or margin floor'); } return ceilDiv(cost * BPS, BPS - floorBps); } // The validated tiers have positive prices and non-negative gross margins. function displayMarginBps(cost: bigint, sell: bigint): bigint { return ((sell - cost) * BPS * 2n + sell) / (2n * sell); } assert.equal(Math.ceil((0.14 / (1 - 0.30)) * 100), 21); assert.equal(minimumSellPrice(parseUsd('0.14'), 3_000n), 20n); assert.throws(() => parseUsd('10.075'), RangeError); 

The price floor comes from sell × (10,000 − floorBps) ≥ cost × 10,000. At a $7.01 landed cost, a 30% floor puts the minimum at $10.02. Use the wholesale margin and keystone calculator to inspect how changing landed cost or a volume discount affects the brand and retailer margins.

Round the MOQ before validating the two buyer tiers

This catalog uses a positive unit MOQ per SKU and a fixed carton size. Divide the requested MOQ by the carton size and add a carton only when the remainder is nonzero. An MOQ of 10 with a case pack of 6 ships as 12 units, while an MOQ of 16 with a pack of 8 stays at 16. For a single-SKU dollar minimum, also round minimum spend ÷ carton price up and use the larger of the two carton counts. A mixed-SKU order minimum belongs on the cart subtotal, where the buyer can meet it with any eligible assortment. The Shopify line sheet MOQ and pack calculator handles unit and dollar minimums for a prepack or carton.

The sample policy requires at least 45% brand margin for boutiques and 30% for distributors. A distributor gets a lower unit price and must commit to more shippable units. Two different raw MOQs can collapse to the same carton count. Compare the rounded quantities before exporting.

type Tier = { unitPrice: bigint; requestedMoq: bigint }; type Sku = { sku: string; landedCost: bigint; casePack: bigint; boutique: Tier; distributor: Tier; }; function wholeCaseMoq(requestedUnits: bigint, unitsPerCase: bigint): bigint { if (requestedUnits <= 0n) throw new RangeError('MOQ must be positive'); return ceilDiv(requestedUnits, unitsPerCase) * unitsPerCase; } function validateSku(row: Sku) { const { sku, landedCost, casePack, boutique, distributor } = row; const boutiqueMinUnits = wholeCaseMoq(boutique.requestedMoq, casePack); const distributorMinUnits = wholeCaseMoq(distributor.requestedMoq, casePack); const boutiqueFloor = minimumSellPrice(landedCost, 4_500n); const distributorFloor = minimumSellPrice(landedCost, 3_000n); if (boutique.unitPrice < boutiqueFloor || distributor.unitPrice < distributorFloor) { throw new RangeError(`${sku}: tier below its brand margin floor`); } if (distributor.unitPrice >= boutique.unitPrice || distributorMinUnits <= boutiqueMinUnits) { throw new RangeError(`${sku}: distributor requires a lower price and a higher full-case MOQ`); } return { msrp: keystoneMsrp(boutique.unitPrice), boutiqueFloor, distributorFloor, boutiqueMinUnits, distributorMinUnits, boutiqueMinOrder: boutique.unitPrice * boutiqueMinUnits, distributorMinOrder: distributor.unitPrice * distributorMinUnits, boutiqueMarginBps: displayMarginBps(landedCost, boutique.unitPrice), distributorMarginBps: displayMarginBps(landedCost, distributor.unitPrice), }; } 

Worked three-SKU line sheet

The MOQ values in the input table are units per SKU. All prices are USD per unit.

SKU Landed cost Case pack Boutique price Boutique requested MOQ Distributor price Distributor requested MOQ
MUG-CLAY $7.01 6 $13.99 10 $10.02 25
TOTE-INK $5.40 8 $10.99 16 $8.00 32
SOAP-CEDAR $3.30 12 $6.99 13 $5.00 37
SKU Keystone MSRP Boutique units Boutique minimum Boutique brand margin Distributor units Distributor minimum Distributor brand margin
MUG-CLAY $27.98 12 $167.88 49.89% 30 $300.60 30.04%
TOTE-INK $21.98 16 $175.84 50.86% 32 $256.00 32.50%
SOAP-CEDAR $13.98 24 $167.76 52.79% 48 $240.00 34.00%

Buying the minimum of all three SKUs costs $511.48 at boutique prices or $796.60 at distributor prices, before freight and tax. For MUG-CLAY alone, adding a $200.00 minimum spend to the boutique's unit MOQ raises the minimum to three cartons, or 18 units at $251.82.

const catalog: Sku[] = [ { sku: 'MUG-CLAY', landedCost: parseUsd('7.01'), casePack: 6n, boutique: { unitPrice: parseUsd('13.99'), requestedMoq: 10n }, distributor: { unitPrice: parseUsd('10.02'), requestedMoq: 25n }, }, { sku: 'TOTE-INK', landedCost: parseUsd('5.40'), casePack: 8n, boutique: { unitPrice: parseUsd('10.99'), requestedMoq: 16n }, distributor: { unitPrice: parseUsd('8.00'), requestedMoq: 32n }, }, { sku: 'SOAP-CEDAR', landedCost: parseUsd('3.30'), casePack: 12n, boutique: { unitPrice: parseUsd('6.99'), requestedMoq: 13n }, distributor: { unitPrice: parseUsd('5.00'), requestedMoq: 37n }, }, ]; const results = catalog.map(validateSku); assert.deepEqual(results.map((row) => [ row.msrp, row.boutiqueMinUnits, row.boutiqueMinOrder, row.boutiqueMarginBps, row.distributorMinUnits, row.distributorMinOrder, row.distributorMarginBps, ]), [ [2798n, 12n, 16_788n, 4989n, 30n, 30_060n, 3004n], [2198n, 16n, 17_584n, 5086n, 32n, 25_600n, 3250n], [1398n, 24n, 16_776n, 5279n, 48n, 24_000n, 3400n], ]); assert.equal(results.reduce((sum, row) => sum + row.boutiqueMinOrder, 0n), 51_148n); assert.equal(results.reduce((sum, row) => sum + row.distributorMinOrder, 0n), 79_660n); const mug = catalog[0]; const cartonPrice = mug.casePack * mug.boutique.unitPrice; const cartonsForSpend = ceilDiv(parseUsd('200.00'), cartonPrice); assert.equal(cartonsForSpend, 3n); assert.equal(cartonsForSpend * mug.casePack, 18n); assert.equal(cartonsForSpend * cartonPrice, 25_182n); assert.equal(results[0].distributorFloor, 1002n); assert.throws(() => validateSku({ ...mug, distributor: { ...mug.distributor, unitPrice: 1001n } })); assert.throws(() => validateSku({ ...mug, distributor: { ...mug.distributor, requestedMoq: 11n } })); // A displayed 30.00% can still miss an exact 30% threshold. assert.equal(displayMarginBps(70_001n, 100_001n), 3000n); assert.ok(100_001n < minimumSellPrice(70_001n, 3000n)); console.table(results); 

Keep the line sheet, CSV, and order form in sync

Use the Shopify variant ID as the internal join key and retain the merchant's SKU for the buyer-facing row. Generate each tier's line sheet and order form from the same validated variant records. Publish the tier's case-rounded MOQ and units per case together. In a Shopify B2B catalog, those correspond to the variant minimum and quantity increment. If you import the values, use the catalog CSV format for quantity rules. Shopify’s B2B quantity rules and volume pricing documentation

Serialize cents as decimal strings at the CSV boundary. For example, 1002n becomes "10.02" by formatting the integer quotient and a two-digit remainder. For a JSON payload named unitPriceCents, serialize the same value as "1002" and restore it to bigint after validation. Keep the price tier and order minimum paired when you review the resulting buyer document. LineSheetPack’s line sheet and order-form workflow