# Monetary / financial calculations inside your QRF → BOQ automation

<div class="paragraph" id="bkmrk-for-monetary-%2F-finan">For **monetary / financial calculations inside your QRF → BOQ automation**, you need two things:</div>1. <div class="paragraph">**Exact decimal precision** (no binary-float rounding surprises).</div>
2. <div class="paragraph">**Convenience helpers** for currency formatting, FX, amortisation, etc.</div>

<div class="paragraph" id="bkmrk-%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80">──────────────────────────────────────────────</div>1. <div class="paragraph">Core precision → `decimal`</div>```python
    from decimal import Decimal, ROUND_HALF_UP
    
    qty   = Decimal('12.50')     # kg
    rate  = Decimal('78.35')     # $/kg
    total = (qty * rate).quantize(Decimal('0.01'), ROUND_HALF_UP)
    ```
2. <div class="paragraph">Money wrapper → `money` or `py-moneyed`</div>```python
    from money import Money
    
    unit_price = Money('78.35', 'USD')
    line_total = Money('12.50', 'USD') * unit_price
    ```
3. <div class="paragraph">Excel / reporting → `openpyxl`, `xlsxwriter` (they both **preserve `Decimal` precision** when you write values).</div>
4. <div class="paragraph">Optional extras  
    • `forex-python` – real-time FX rates for multi-currency bids.  
    • `numpy-financial` – NPV, IRR, loan amortisation if you need financing tables.  
    • `babel` – locale-aware currency formatting.</div>

<div class="paragraph" id="bkmrk-%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80%E2%94%80-1">──────────────────────────────────────────────  
Quick recipe (fits your Python stack):</div>```python
from decimal import Decimal
from openpyxl import Workbook
from money import Money

wb = Workbook()
ws = wb.active
ws.append(['Item', 'Qty (kg)', 'Rate ($)', 'Amount ($)'])

for item, qty, rate in [
        ('Column UC203', Decimal('253.4'), Decimal('1.08')),
        ('Beam UB305', Decimal('417.9'), Decimal('1.08'))]:
    amount = Money(qty * rate, 'USD')
    ws.append([item, float(qty), float(rate), str(amount)])

wb.save('BOQ_financial.xlsx')
```

<div data-v-e8248998="" id="bkmrk-">  
</div><div class="paragraph" id="bkmrk-all-values-stay-exac">All values stay exact (no rounding errors), and the worksheet shows standard $-formatting.</div>