Fuel Cost Calculator In Malaysia
Also Visit : Car Insurance Calculator
Sample Fuel Cost Calculator:
import React, { useState } from 'react';
export default function FuelCostCalculator() {
const [distance, setDistance] = useState('');
const [fuelEfficiency, setFuelEfficiency] = useState('');
const [fuelPrice, setFuelPrice] = useState('');
const [fuelCost, setFuelCost] = useState(null);
const calculateFuelCost = () => {
if (distance && fuelEfficiency && fuelPrice) {
const cost = (distance / fuelEfficiency) * fuelPrice;
setFuelCost(cost.toFixed(2));
}
};
return (
<div className="calculator">
<h2>Fuel Cost Calculator</h2>
<label>
Distance (km):
<input type="number" value={distance} onChange={(e) => setDistance(e.target.value)} />
</label>
<label>
Fuel Efficiency (km/l):
<input type="number" value={fuelEfficiency} onChange={(e) => setFuelEfficiency(e.target.value)} />
</label>
<label>
Fuel Price per Liter (RM):
<input type="number" value={fuelPrice} onChange={(e) => setFuelPrice(e.target.value)} />
</label>
<button onClick={calculateFuelCost}>Calculate</button>
{fuelCost !== null && <p>Estimated Fuel Cost: RM {fuelCost}</p>}
</div>
);
}