VBC-007: float-for-currency
errorCategory: security
Analysis: Regex (line by line)
File types: .js, .ts, .tsx, .py, .astro
Scope: source code only, ignoring anything inside strings and comments
Excluded paths: **/test/**, **/tests/**, **/__tests__/**, **/testdata/**, **/fixtures/**, **/test_*.py, **/*_test.py, **/test.py, **/conftest.py, **/*_test.go, **/*.test.*, **/*.spec.*
Tags: security clean-code
What it reports
Monetary value declared as a floating point literal at line {line}. Binary floats cannot represent decimal cents exactly. Store money as integer minor units or use a decimal type.
Flagged
js
const unitPrice = 19.99;js
let taxRate = 0.22;js
totalCost: 4.50js
const weightedPrice = 4.5;Not flagged
js
const unitPriceCents = 1999;js
cost_weight = 0.3js
const cfg = { costWeight: 0.7 };js
const priceRatio = 0.5;ts
const unitPrice = 19.99;js
const ratio = 0.22;js
const feedback = 0.5;js
const amount = 0.5;js
const coffee = 1.5;Pattern
regex
\b(?:(?:price|cost|fee|fees|tax|subtotal|payment|invoice|salary|refund|charge)(?![a-z])|[a-z_$]+(?:Price|Cost|Fee|Fees|Tax|Subtotal|Payment|Invoice|Salary|Refund|Charge)(?![a-z]))(?![A-Za-z_$]*(?:[Ww]eight|[Rr]atio|[Ss]core|[Ff]actor|[Tt]hreshold|[Pp]enalty|[Mm]ultiplier|[Bb]ias|[Cc]oef))[A-Za-z_$]*\s*[:=]\s*[0-9]+\.[0-9]+