Skip to content

bug: Gas calculator division by zero when carConsumption is 0 #22

@TemaDeveloper

Description

@TemaDeveloper

Description

In src/lib/gas-calculator.ts, if carConsumption is set to 0 by the user, the formula (totalKm / 100) * 0 produces 0 litres, which is mathematically correct but misleading. However costPerKm divides by totalKm which could produce Infinity if totalKm is 0 but totalCostDollars is non-zero (impossible given the formula, but defensive coding is better).

Fix

Add validation: if (config.carConsumptionLPer100km <= 0) return { totalKm, litresUsed: 0, totalCostDollars: 0, costPerKm: 0 }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions