const parse = value => { const match = String(value).match(/^(\d+)(?:\.(\d{1,2}))?$/); if (!match) throw Object.assign(new Error("Invalid money"), { code: "INVALID_MONEY", status: 400 }); return BigInt(match[1]) * 100n + BigInt((match[2] || "").padEnd(2, "0")); }; const format = cents => `${cents / 100n}.${String(cents % 100n).padStart(2, "0")}`; const subtractFloor = (a, b) => format(parse(a) > parse(b) ? parse(a) - parse(b) : 0n); const percentOff = (amount, percent) => { const [whole,fraction=""] = String(percent).split("."); const basis = BigInt(whole) * 100n + BigInt(fraction.padEnd(2,"0")); return format(parse(amount) * basis / 10000n); }; module.exports = { parse, format, subtractFloor, percentOff };