Monetary / financial calculations inside your QRF → BOQ automation
For monetary / financial calculations inside your QRF → BOQ automation, you need two things:
-
Exact decimal precision (no binary-float rounding surprises).
-
Convenience helpers for currency formatting, FX, amortisation, etc.
──────────────────────────────────────────────
-
Core precision →
decimalfrom 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) -
Money wrapper →
moneyorpy-moneyedfrom money import Money unit_price = Money('78.35', 'USD') line_total = Money('12.50', 'USD') * unit_price -
Excel / reporting →
openpyxl,xlsxwriter(they both preserveDecimalprecision when you write values). -
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.
──────────────────────────────────────────────
Quick recipe (fits your Python stack):
Quick recipe (fits your Python stack):
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')
All values stay exact (no rounding errors), and the worksheet shows standard $-formatting.
No Comments