Tài liệu thanh toán thương mại đòi hỏi tính nhất quán toán học tuyệt đối đến từng đơn vị tiền tệ nhỏ nhất. Dưới đây là lược đồ dữ liệu JSON đại diện cho một phiên làm việc hóa đơn hoàn chỉnh trong Utiliome:
{
"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
}
}
Để ngăn ngừa sự thiếu chính xác trong phép làm tròn dấu phẩy động theo chuẩn IEEE 754 (chẳng hạn như 0.1 + 0.2 === 0.30000000000000004), các phép tính được xử lý theo đơn vị tiền tệ phụ dạng số nguyên (cents hoặc xu):
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;