To split a loan payment into principal and interest in code, compute each month's interest as the outstanding balance times the annual rate divided by 12, rounded to the cent, and treat the rest of the payment as principal. Then emit a balanced journal entry per payment and check the running balance against the lender's statement. ZeraBooks' ledger does the same thing in its own code, never in the AI.
I'm on the ZeraBooks team. Loan payments are a nice small example of a rule we hold to everywhere: the AI decides what a bank line is ("this is a payment on the equipment loan"), and deterministic code does the math. Here's that code, simplified, in Python.
Payment amount
For a fixed-rate amortizing loan, the level payment is the standard annuity formula:
from decimal import Decimal , ROUND_HALF_UP , getcontext
getcontext ().…