A warehouse charge import needs an explicit amount format. Converting arbitrary text with Number() before validation can erase distinctions the import should reject. A Shopify 3PL reporting adapter can instead validate a declared decimal format and convert its digits directly to integer minor units.
This example accepts nonnegative ASCII decimal strings with exactly two fractional digits and at most twelve integer digits. The scale and maximum length are local example rules, not universal currency rules or a provider's prices.
Convert validated digits, not a floating-point amount
'use strict';
const assert = require('node:assert/strict');
function minorUnits(text) {
if (typeof text !== 'string' || text.length > 15) {
throw new Error('Bounded decimal text required');
}
const match = /^(0|[1-9][0-9]{0,11})\.([0-9]{2})$/.exec(text);
if (!match || match[0] !== text) {
throw new Error('Expected nonnegative amount with two decimals');
}
return BigInt(match[1]) * 100n + BigInt(match[2]);
}
assert.equal(minorUnits('0.00'), 0n);
assert.equal(minorUnits('1.05'), 105n);
assert.equal(minorUnits('999999999999.99'), 99999999999999n);
assert.equal(minorUnits('0.10') + minorUnits('0.20'), 30n);
assert.equal(typeof minorUnits('1.00'), 'bigint');
for (const value of [
'', ' ', '1', '1.0', '1.000', '.50', '00.50',
'-1.00', '+1.00', '1e2', '1,000.00', '1,50',
' 1.00', '1.00 ', '1.00\n', '1.00',
'1000000000000.00', 1.05, null, undefined
]) assert.throws(() => minorUnits(value));
assert.equal(minorUnits('1.00').toString(), '100');
assert.throws(() => JSON.stringify({ amount: minorUnits('1.00') }));
console.log('Two-decimal charge parsing checks passed');
Save as decimal-charge.cjs and run node decimal-charge.cjs with Node.js 24. These local assertions check the accepted boundary, exact addition, input types, signs, separators, exponent notation, extra precision and trailing whitespace. The numbers are synthetic parser tests, not quoted fulfillment charges.
BigInt supports integer arithmetic, but it does not mix directly with Number arithmetic and is not serialized by default with JSON.stringify(). The last assertions make the output contract visible: serialize the integer as a decimal string when that is what the receiving contract requires, and retain its currency and scale alongside it.
Keep billing meaning outside the parser
A drop shipping charge and a shopify fulfillment charge can use the same numeric syntax while describing different work. A parsed amount says nothing about its charging unit, applicable currency, approval or whether tax and transport are included.
For China fulfillment, map those fields separately before comparing totals. A China 3PL interface may require another scale or signed adjustments; that needs an explicit schema change, not silent rounding or a broader conversion function.
In a hypothetical cost-import brief named “International Fulfillment for Folligen,” confirm that contract before choosing the parser. I work with YX Fulfillment; its itemized cost comparison guide supplies operational context for the fields a charge represents. These executed tests establish parsing behavior, without claiming a live billing integration.
Warehouse workstations and equipment.

Top comments (0)