Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Perpetuity Calculator #1989

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Calculators/Perpetuity-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# <p align="center">Perpetuity Calculator</p>

## Description :-

A simple and interactive tool to calculate the **present value (PV)** of a perpetuity, an infinite series of cash flows, using the formula:

**PV = C / r**

Where:
- **PV** is the present value
- **C** is the annual cash flow
- **r** is the discount rate

This tool makes financial calculations easier and helps users understand perpetuities better.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Features :-

- **Perpetuity Calculation**: Input fields to calculate present value based on cash flow and discount rate.
- **Reset Functionality**: Clear all fields and results with a single click.
- **Error Handling**: Alerts users with meaningful error messages for invalid inputs.
- **Tooltips**: User guidance on input requirements.
- **Responsive Design**: Adapts to all devices for seamless usability.

## Formula :-

**Present Value = Cash Flow / Discount Rate**

## Screenshots :-

![image](https://github.com/user-attachments/assets/a68ff8ad-781a-4943-a125-4e1b2a57cf5a)
38 changes: 38 additions & 0 deletions Calculators/Perpetuity-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Perpetuity Calculator</title>
</head>

<body>
<div class="calculator">
<h1>Perpetuity Calculator</h1>
<p>Calculate the present value of an infinite series of cash flows.</p>

<div class="input-section">
<label for="cashFlow">Annual Cash Flow (C):</label>
<input type="number" id="cashFlow" placeholder="Enter cash flow" step="0.01">
<span class="tooltip">Example: 1000</span>

<label for="discountRate">Discount Rate (r %):</label>
<input type="number" id="discountRate" placeholder="Enter discount rate" step="0.01">
<span class="tooltip">Example: 5 (for 5%)</span>
</div>

<button id="calculateBtn">Calculate</button>
<button id="resetBtn">Reset</button>

<div id="output">
<h2>Result:</h2>
<p id="presentValue">Present Value (PV): --</p>
</div>
</div>

<script src="script.js"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions Calculators/Perpetuity-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
document.getElementById("calculateBtn").addEventListener("click", () => {
const cashFlow = parseFloat(document.getElementById("cashFlow").value);
const discountRate = parseFloat(document.getElementById("discountRate").value);

if (isNaN(cashFlow) || cashFlow <= 0) {
alert("Please enter a valid annual cash flow (greater than 0).");
return;
}

if (isNaN(discountRate) || discountRate <= 0 || discountRate >= 100) {
alert("Please enter a valid discount rate (greater than 0 and less than 100).");
return;
}

const rateDecimal = discountRate / 100;
const presentValue = cashFlow / rateDecimal;

document.getElementById("presentValue").textContent = `Present Value (PV): ${presentValue.toFixed(2)}`;
});

document.getElementById("resetBtn").addEventListener("click", () => {
document.getElementById("cashFlow").value = "";
document.getElementById("discountRate").value = "";
document.getElementById("presentValue").textContent = "Present Value (PV): --";
});
85 changes: 85 additions & 0 deletions Calculators/Perpetuity-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #2b5876, #4e4376);
color: white;
text-align: center;
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}

.calculator {
background-color: rgba(0, 0, 0, 0.8);
border-radius: 15px;
padding: 20px 30px;
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

h1 {
margin-bottom: 10px;
font-size: 26px;
color: #84cef5;
}

p {
margin-bottom: 15px;
font-size: 16px;
}

.input-section label {
display: block;
margin: 10px 0 5px;
font-size: 14px;
color: #ccc;
}

input {
padding: 10px;
width: calc(100% - 20px);
margin-bottom: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
}

.tooltip {
font-size: 12px;
color: #aaa;
display: block;
margin-bottom: 10px;
}

button {
padding: 10px 20px;
background-color: #84cef5;
border: none;
border-radius: 5px;
font-size: 16px;
color: white;
cursor: pointer;
margin: 5px;
transition: transform 0.3s ease;
}

button:hover {
transform: scale(1.1);
background-color: #67b3e1;
}

#output {
margin-top: 20px;
}

#presentValue {
font-size: 18px;
font-weight: bold;
}

@media (max-width: 768px) {
body {
padding: 20px;
}
}
6 changes: 6 additions & 0 deletions calculators.json
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,12 @@
"link": "./Calculators/Permutation-Combination-Calculator/index.html",
"source": "https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Permutation-Combination-Calculator"
},
{
"title": "Perpetuity Calculator",
"description": "Calculates the present value of a perpetuity.",
"link": "./Calculators/Perpetuity-Calculator/index.html",
"source": "https://github.com/username/CalcDiverse/tree/main/Calculators/Perpetuity-Calculator"
},
{
"title": "Pet Age Calculator",
"description": "Calculates a pet's age in human years.",
Expand Down
Loading