Decimal represents financial amounts more safely than floating point when an application must preserve the intended base-ten value. It is especially useful for ACH debit and credit totals, where a small conversion surprise can become a visible data or reporting problem. section 7.3
Construct a Decimal from the original string, not from a float. For example, Decimal('0.1') preserves 0.1, while Decimal(0.1) carries the floating-point approximation into the Decimal value. When parsing a fixed-width amount, first assemble the whole and fractional slices into a decimal string. section 7.3 section 7.3
Parse an ACH total
A file-control record can split an amount across digit positions: Decimal(f"{record[31:41]}.{record[41:43]}"). The resulting value can be stored in a NUMERIC(12, 2) database field and returned as a typed credit or debit total. section 7.3 section 7.3 section 7.3
Using Decimal affects every boundary that carries money. Database columns can enforce numeric formatting, API response models can declare Decimal totals, and client-side response data may arrive as strings before being converted into Decimal values. Keep these representations explicit rather than assuming a numeric-looking value is already safe for arithmetic. section 7.3 section 7.3 section 7.4.2
Decimal arithmetic may use methods rather than the ordinary plus operator in the dashboard code. After converting debit and credit totals, compute a combined amount with creditTotal.add(debitTotal), preserving a consistent Decimal value through the calculation. section 7.4.2
Listing 7.4 Converting the string to a number that includes a decimal point
total_debit_entry_dollar_amount= #1
Decimal(f"{record[31:41]}.{record[41:43]}"), #1
total_credit_entry_dollar_amount= #1
Decimal(f"{record[43:53]}.{record[53:55]}"), #1
Shows the fixed-width parsing pattern: build a decimal string from whole and fractional record slices, then pass it to Decimal. section 7.3




