商业开票单据必须在最小货币分数单位上保持严密的数学一致性。以下是在 Utiliome 中表示当前活动发票会话的运行期 JSON 数据架构:
{
"meta": {
"invoiceNumber": "INV-2026-0891",
"issueDate": "2026-11-07",
"dueDate": "2026-12-07",
"currency": "USD",
"currencySymbol": "$"
},
"issuer": {
"name": "Apex Cloud Architecture LLC",
"address": "100 Montgomery St, Suite 1400",
"city": "San Francisco, CA 94104",
"taxId": "US-EIN-94-3829102"
},
"client": {
"name": "Nexus Global Logistics Inc",
"address": "450 Lexington Ave, 8th Floor",
"city": "New York, NY 10017",
"taxId": "US-EIN-13-8829104"
},
"items": [
{
"description": "Infrastructure Security Audit & Hardening",
"quantity": 40,
"unitRate": 225.00,
"amount": 9000.00
},
{
"description": "Zero-Trust Kubernetes Cluster Configuration",
"quantity": 1,
"unitRate": 4500.00,
"amount": 4500.00
}
],
"financials": {
"subtotal": 13500.00,
"discountPercent": 5.0,
"discountAmount": 675.00,
"taxPercent": 8.5,
"taxAmount": 1090.13,
"total": 13915.13
}
}
为了防止 IEEE 754 浮点舍入偏差(例如 0.1 + 0.2 === 0.30000000000000004),所有计算均在货币次级单位(分/Cents)的整型环境下处理:
const subtotalCents = items.reduce((sum, item) => {
return sum + Math.round(item.quantity * item.unitRate * 100);
}, 0);
const discountCents = Math.round(subtotalCents * (discountPercent / 100));
const taxableCents = subtotalCents - discountCents;
const taxCents = Math.round(taxableCents * (taxPercent / 100));
const totalCents = taxableCents + taxCents;