Car Percentage Rate Calculator
This calculator helps you determine the percentage rate of a car's value that a specific cost represents. This is useful for understanding what proportion of your car's overall worth a particular expense or value is.
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-container p {
text-align: center;
margin-bottom: 30px;
color: #555;
line-height: 1.5;
}
.input-section {
display: flex;
flex-direction: column;
gap: 15px;
margin-bottom: 20px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"] {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.calculator-container button {
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.result-section {
text-align: center;
margin-top: 20px;
padding-top: 20px;
border-top: 1px solid #eee;
}
.result-section h3 {
margin-bottom: 10px;
color: #333;
}
#percentageRateResult {
font-size: 20px;
font-weight: bold;
color: #28a745;
}
function calculatePercentageRate() {
var carValueInput = document.getElementById("carValue");
var specificCostInput = document.getElementById("specificCost");
var resultDiv = document.getElementById("percentageRateResult");
var carValue = parseFloat(carValueInput.value);
var specificCost = parseFloat(specificCostInput.value);
if (isNaN(carValue) || isNaN(specificCost)) {
resultDiv.innerHTML = "Please enter valid numbers for both values.";
resultDiv.style.color = "red";
return;
}
if (carValue <= 0) {
resultDiv.innerHTML = "Total car value must be greater than zero.";
resultDiv.style.color = "red";
return;
}
if (specificCost < 0) {
resultDiv.innerHTML = "Specific cost cannot be negative.";
resultDiv.style.color = "red";
return;
}
var percentageRate = (specificCost / carValue) * 100;
resultDiv.innerHTML = percentageRate.toFixed(2) + "%";
resultDiv.style.color = "#28a745";
}