Interest Principal Calculator: Understand Your Loan's Core
:root {
–primary-color: #004a99;
–success-color: #28a745;
–background-color: #f8f9fa;
–text-color: #333;
–border-color: #ddd;
–card-background: #fff;
–shadow: 0 2px 4px rgba(0,0,0,.1);
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: var(–background-color);
color: var(–text-color);
line-height: 1.6;
margin: 0;
padding: 0;
}
.container {
max-width: 960px;
margin: 20px auto;
padding: 20px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: var(–shadow);
}
header {
text-align: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid var(–border-color);
}
header h1 {
color: var(–primary-color);
margin-bottom: 10px;
}
.loan-calc-container {
background-color: var(–card-background);
padding: 25px;
border-radius: 8px;
box-shadow: var(–shadow);
margin-bottom: 30px;
}
.input-group {
margin-bottom: 20px;
text-align: left;
}
.input-group label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: var(–primary-color);
}
.input-group input[type="number"],
.input-group input[type="text"],
.input-group select {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid var(–border-color);
border-radius: 4px;
font-size: 1rem;
box-sizing: border-box;
}
.input-group input[type="number"]:focus,
.input-group input[type="text"]:focus,
.input-group select:focus {
border-color: var(–primary-color);
outline: none;
box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2);
}
.input-group .helper-text {
font-size: 0.85rem;
color: #6c757d;
margin-top: 5px;
display: block;
}
.error-message {
color: #dc3545;
font-size: 0.85rem;
margin-top: 5px;
display: none; /* Hidden by default */
}
.error-message.visible {
display: block;
}
.button-group {
display: flex;
justify-content: space-between;
margin-top: 25px;
gap: 10px;
}
.button-group button {
padding: 12px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: background-color 0.3s ease;
flex: 1;
}
.button-group button.primary {
background-color: var(–primary-color);
color: white;
}
.button-group button.primary:hover {
background-color: #003366;
}
.button-group button.secondary {
background-color: #6c757d;
color: white;
}
.button-group button.secondary:hover {
background-color: #5a6268;
}
.results-container {
margin-top: 30px;
padding: 25px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: var(–shadow);
}
.results-container h2 {
color: var(–primary-color);
margin-bottom: 20px;
text-align: center;
}
.main-result {
background-color: var(–success-color);
color: white;
padding: 20px;
text-align: center;
border-radius: 5px;
margin-bottom: 20px;
font-size: 1.8rem;
font-weight: bold;
}
.intermediate-results div,
.formula-explanation {
margin-bottom: 15px;
padding: 10px;
border-left: 4px solid var(–primary-color);
background-color: #e9ecef;
border-radius: 4px;
}
.intermediate-results span,
.formula-explanation span {
font-weight: bold;
color: var(–primary-color);
}
.chart-container {
margin-top: 30px;
padding: 25px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: var(–shadow);
text-align: center;
}
.chart-container h3 {
color: var(–primary-color);
margin-bottom: 20px;
}
canvas {
max-width: 100%;
height: auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid var(–border-color);
}
th {
background-color: var(–primary-color);
color: white;
font-weight: bold;
}
td {
background-color: #f1f1f1;
}
caption {
font-size: 1.1rem;
font-weight: bold;
color: var(–primary-color);
margin-bottom: 10px;
caption-side: top;
text-align: left;
}
.article-section {
margin-top: 40px;
padding: 30px;
background-color: var(–card-background);
border-radius: 8px;
box-shadow: var(–shadow);
}
.article-section h2, .article-section h3 {
color: var(–primary-color);
margin-bottom: 15px;
}
.article-section h2 {
border-bottom: 2px solid var(–primary-color);
padding-bottom: 10px;
}
.article-section p {
margin-bottom: 15px;
}
.article-section ul, .article-section ol {
margin-left: 20px;
margin-bottom: 15px;
}
.article-section li {
margin-bottom: 8px;
}
.faq-item {
margin-bottom: 15px;
padding: 10px;
border: 1px solid var(–border-color);
border-radius: 4px;
}
.faq-item .question {
font-weight: bold;
color: var(–primary-color);
cursor: pointer;
display: block;
padding: 5px;
}
.faq-item .answer {
display: none;
margin-top: 10px;
padding: 5px;
font-size: 0.95rem;
}
.faq-item .answer.visible {
display: block;
}
.related-links {
margin-top: 30px;
padding: 20px;
background-color: #e9ecef;
border-radius: 8px;
}
.related-links h3 {
color: var(–primary-color);
margin-bottom: 15px;
}
.related-links ul {
list-style: none;
padding: 0;
}
.related-links li {
margin-bottom: 10px;
}
.related-links a {
color: var(–primary-color);
text-decoration: none;
font-weight: bold;
}
.related-links a:hover {
text-decoration: underline;
}
.related-links p {
font-size: 0.9rem;
color: #555;
margin-top: 5px;
}
.highlight {
background-color: var(–success-color);
color: white;
padding: 2px 5px;
border-radius: 3px;
}
.formula-explanation code {
background-color: #e0e0e0;
padding: 2px 4px;
border-radius: 3px;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
}
Calculation Results
—
The principal is calculated by subtracting the total interest paid from the total amount repaid.
Principal = Total Repaid - Total Interest Paid
Estimates for interest rate and loan term are based on common financial models and may vary.
Loan Repayment Breakdown
Distribution of Principal vs. Interest Over Time (Estimated)
Key Financial Metrics
| Metric |
Value |
| Total Amount Repaid |
— |
| Total Interest Paid |
— |
| Principal Amount |
— |
| Estimated Interest Rate |
— |
| Estimated Loan Term (Months) |
— |
What is an Interest Principal Calculator?
An interest principal calculator is a specialized financial tool designed to help individuals and businesses understand the fundamental components of a loan. It works backward from the total amount repaid and the total interest paid to determine the original loan principal. This is crucial for comprehending the true cost of borrowing and the underlying debt structure. Unlike simple interest calculators that focus on calculating interest for a given principal, this tool helps you dissect a loan's repayment to find its starting point.
Who should use it?
- Borrowers who want to understand the principal amount of a loan they've already paid off or are currently paying.
- Individuals trying to verify loan statements or identify discrepancies.
- Financial planners and advisors assessing loan portfolios.
- Students learning about loan amortization and financial mathematics.
Common Misconceptions:
- Confusing Principal with Total Repayment: Many people think the total amount they pay back is the principal. In reality, the principal is just the initial borrowed amount; the total repayment includes interest.
- Underestimating Interest: Failing to account for the total interest paid can lead to a misunderstanding of the loan's true cost. This calculator highlights that difference.
- Assuming Simple Interest: Most loans use compound interest, which means interest accrues on both the principal and previously accumulated interest. This calculator helps infer aspects of the loan that reflect this complexity.
Interest Principal Calculator Formula and Mathematical Explanation
The core of the interest principal calculator relies on a straightforward subtraction. When you repay a loan, your payments are allocated towards both the principal amount borrowed and the interest accrued. The total amount you repay is the sum of these two components.
The Basic Formula
The fundamental formula used is:
Principal = Total Repaid - Total Interest Paid
Where:
- Principal: The original amount of money borrowed.
- Total Repaid: The entire sum of money paid back to the lender over the life of the loan, including all installments.
- Total Interest Paid: The total cost of borrowing the money, which is the difference between the total amount repaid and the original principal.
Derivation and Variables
Let's break down the variables and their meanings:
| Variable |
Meaning |
Unit |
Typical Range |
| P |
Principal Loan Amount |
Currency ($) |
$100 – $1,000,000+ |
| Itotal |
Total Interest Paid |
Currency ($) |
$0 – $500,000+ |
| TR |
Total Amount Repaid |
Currency ($) |
$100 – $1,500,000+ |
| r |
Annual Interest Rate |
% |
1% – 30%+ |
| n |
Loan Term (in months) |
Months |
1 – 360+ |
The relationship is: TR = P + Itotal. Therefore, to find the principal (P), we rearrange this to: P = TR - Itotal.
The calculator also provides estimates for the interest rate (r) and loan term (n). These are derived using financial formulas that approximate these values based on the calculated principal, total interest, and common loan structures (like amortizing loans). For instance, an estimated interest rate might be calculated using iterative methods or approximations based on the loan amount, total interest, and term. The estimated loan term is often inferred by assuming a standard payment frequency and calculating how many periods it would take to amortize the principal with the given interest.
Practical Examples (Real-World Use Cases)
Example 1: Understanding a Paid-Off Car Loan
Sarah recently paid off her car loan. She remembers making a total of $25,000 in payments over the years. Her loan statement shows she paid $5,000 in interest. She wants to know the original price of the car she financed.
- Input: Total Amount Repaid = $25,000
- Input: Total Interest Paid = $5,000
Using the interest principal calculator:
Principal = $25,000 (Total Repaid) – $5,000 (Total Interest Paid) = $20,000
Result: The original principal amount (car price financed) was $20,000. The calculator might also estimate the interest rate and loan term based on these figures, providing Sarah with a clearer picture of her car financing.
Example 2: Analyzing a Personal Loan
John took out a personal loan to consolidate debt. He paid back a total of $15,000. He knows that $3,000 of that amount was interest.
- Input: Total Amount Repaid = $15,000
- Input: Total Interest Paid = $3,000
Using the interest principal calculator:
Principal = $15,000 (Total Repaid) – $3,000 (Total Interest Paid) = $12,000
Result: John's original personal loan principal was $12,000. This helps him understand how much of his payments went towards the actual debt versus the cost of borrowing. He can use this information to compare with other loan offers or assess his past financial decisions.
How to Use This Interest Principal Calculator
Our interest principal calculator is designed for simplicity and clarity. Follow these steps to get your results:
- Locate the Input Fields: You'll see two main input fields: "Total Amount Repaid ($)" and "Total Interest Paid ($)".
- Enter Total Amount Repaid: Input the complete sum of all payments you have made towards the loan throughout its entire duration. This is the grand total you paid back to the lender.
- Enter Total Interest Paid: Input the total amount of interest you paid over the life of the loan. This figure is often found on final loan statements or can be calculated by subtracting the original principal from the total repaid.
- View Results Instantly: As soon as you enter valid numbers, the calculator will automatically update.
How to Read Results:
- Principal Amount: This is the primary result, showing the original amount you borrowed.
- Estimated Interest Rate: This provides an approximation of the annual interest rate based on the inputs.
- Estimated Loan Term (Months): This estimates the duration of the loan in months.
- Chart and Table: The chart visually breaks down the repayment, and the table summarizes all key metrics for easy reference.
Decision-Making Guidance:
Understanding your principal is key. If the calculated principal seems lower than expected, it might indicate higher interest costs or a longer loan term than initially perceived. Use these insights to make informed decisions about future borrowing, refinancing options, or debt management strategies. For instance, knowing the principal helps you calculate the effective interest rate more accurately, which is vital for comparing different loan products.
Key Factors That Affect Interest Principal Calculator Results
While the core calculation of principal is straightforward subtraction, the *inferred* values like interest rate and loan term are influenced by several interconnected financial factors. Understanding these helps interpret the calculator's output more effectively:
- Interest Rate (r): A higher interest rate means more of your total repayment goes towards interest, thus reducing the proportion attributed to the principal for a fixed total repayment. Conversely, a lower rate means more of your payments go towards reducing the principal. This is a primary driver of the total interest paid.
- Loan Term (n): Longer loan terms generally result in higher total interest paid, even with the same principal and interest rate, because interest has more time to accrue. This impacts the relationship between total repayment and principal.
- Loan Type and Amortization Schedule: Most loans are amortizing, meaning payments are structured so that early payments cover more interest and later payments cover more principal. This calculator infers aspects of this schedule. Non-amortizing loans (like interest-only) would have different dynamics.
- Fees and Charges: Origination fees, late fees, or other charges can increase the total amount repaid without directly increasing the principal. If these are included in "Total Repaid" but not "Total Interest Paid," they can skew the principal calculation.
- Payment Frequency: Paying monthly versus bi-weekly can slightly alter the total interest paid and the loan term due to more frequent principal reduction or extra payments. This affects the accuracy of inferred loan terms.
- Inflation and Economic Conditions: While not directly in the calculation, inflation affects the purchasing power of money. A loan taken out when inflation is high might have a lower real principal value than its nominal value suggests. Lenders factor expected inflation into interest rates.
- Prepayment Penalties/Benefits: Making extra payments can reduce the total interest paid and shorten the loan term. Conversely, penalties for early repayment can increase the total cost.
Frequently Asked Questions (FAQ)
What is the difference between principal and interest?
The principal is the original amount of money borrowed. Interest is the cost of borrowing that money, expressed as a percentage of the principal.
Can the principal be negative?
No, the principal amount borrowed cannot be negative. It represents the initial sum of money.
How is the 'Total Interest Paid' usually determined?
It's typically calculated by subtracting the original principal from the total amount repaid over the loan's life. Lenders provide this information on statements.
Does this calculator assume simple or compound interest?
The core calculation (Principal = Total Repaid – Total Interest Paid) is independent of the interest type. However, the *inferred* interest rate and loan term estimates are based on standard compound interest amortization models.
What if I don't know the exact Total Interest Paid?
If you know the original principal and the total amount repaid, you can calculate the total interest paid: Total Interest Paid = Total Repaid - Original Principal. You might need to use another calculator to find the original principal first if it's unknown.
Can this calculator be used for mortgages?
Yes, absolutely. Mortgages are loans, and this calculator can help you understand the principal component if you know the total payments and total interest paid for your mortgage.
What does the estimated interest rate mean?
The estimated interest rate is an approximation of the annual percentage rate (APR) based on the principal, total interest paid, and estimated loan term. It's a useful metric for comparison but may not be the exact contractual rate due to rounding or specific loan structures.
How accurate are the estimated loan term and interest rate?
These are estimates derived from the primary inputs. Their accuracy depends on the consistency of payments, the loan's amortization schedule, and whether all fees were included in the total repayment figure. They provide a good general understanding.
var chartInstance = null;
function getElement(id) {
return document.getElementById(id);
}
function validateInput(value, id, min, max, message) {
var errorElement = getElement(id + 'Error');
if (value === "") {
errorElement.textContent = "This field cannot be empty.";
errorElement.classList.add('visible');
return false;
}
var numValue = parseFloat(value);
if (isNaN(numValue)) {
errorElement.textContent = "Please enter a valid number.";
errorElement.classList.add('visible');
return false;
}
if (numValue max) {
errorElement.textContent = "Value cannot exceed " + max.toLocaleString() + ".";
errorElement.classList.add('visible');
return false;
}
errorElement.textContent = "";
errorElement.classList.remove('visible');
return true;
}
function calculatePrincipal() {
var totalRepaymentInput = getElement("totalRepayment");
var totalInterestPaidInput = getElement("totalInterestPaid");
var totalRepayment = parseFloat(totalRepaymentInput.value);
var totalInterestPaid = parseFloat(totalInterestPaidInput.value);
var isValidTotalRepayment = validateInput(totalRepaymentInput.value, "totalRepayment", 0, Infinity, "Total repayment must be a positive value.");
var isValidTotalInterestPaid = validateInput(totalInterestPaidInput.value, "totalInterestPaid", 0, Infinity, "Total interest paid must be a positive value.");
if (!isValidTotalRepayment || !isValidTotalInterestPaid) {
resetResults();
return;
}
if (totalInterestPaid > totalRepayment) {
getElement("totalInterestPaidError").textContent = "Total interest paid cannot be greater than total repayment.";
getElement("totalInterestPaidError").classList.add('visible');
resetResults();
return;
} else {
getElement("totalInterestPaidError").textContent = "";
getElement("totalInterestPaidError").classList.remove('visible');
}
var principal = totalRepayment – totalInterestPaid;
// Estimating Interest Rate and Loan Term (simplified approximations)
// These are complex calculations and require assumptions.
// For simplicity, we'll use rough estimates. A real-world scenario
// would involve iterative calculations or more complex formulas.
var estimatedInterestRate = "–";
var estimatedLoanTerm = "–";
if (principal > 0 && totalInterestPaid > 0) {
// Rough estimate for interest rate: Assume a common loan term like 60 months
// This is a highly simplified estimation.
var assumedTermMonths = 60;
var monthlyPaymentEstimate = (totalRepayment) / assumedTermMonths;
var rateEstimate = calculateRateFromAmortization(principal, monthlyPaymentEstimate, assumedTermMonths);
estimatedInterestRate = isNaN(rateEstimate) ? "–" : (rateEstimate * 100).toFixed(2) + "%";
// Rough estimate for loan term: Assume a common interest rate like 5%
// This is also a simplified estimation.
var assumedRate = 0.05; // 5% annual rate
var termEstimate = calculateTermFromAmortization(principal, totalInterestPaid, assumedRate);
estimatedLoanTerm = isNaN(termEstimate) ? "–" : Math.round(termEstimate) + " months";
}
getElement("mainResult").textContent = "$" + principal.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
getElement("principalResult").querySelector("span").textContent = "$" + principal.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
getElement("interestRateEstimate").querySelector("span").textContent = estimatedInterestRate;
getElement("loanTermEstimate").querySelector("span").textContent = estimatedLoanTerm;
// Update table
getElement("tableTotalRepaid").textContent = "$" + totalRepayment.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
getElement("tableTotalInterestPaid").textContent = "$" + totalInterestPaid.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
getElement("tablePrincipal").textContent = "$" + principal.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
getElement("tableInterestRate").textContent = estimatedInterestRate;
getElement("tableLoanTerm").textContent = estimatedLoanTerm;
updateChart(principal, totalInterestPaid);
}
// Helper functions for rate and term estimation (simplified)
// These are complex financial calculations. For a production calculator,
// a robust financial library or more detailed iterative methods would be used.
// Simplified function to estimate rate given P, M, n
function calculateRateFromAmortization(principal, monthlyPayment, termMonths) {
if (principal <= 0 || monthlyPayment <= 0 || termMonths <= 0) return NaN;
var low = 0.0001; // Minimum possible rate
var high = 1.0; // Maximum possible rate (100%)
var rate = NaN;
for (var i = 0; i < 100; i++) { // Iterate to find rate
var mid = (low + high) / 2;
var calculatedPayment = principal * (mid * Math.pow(1 + mid, termMonths)) / (Math.pow(1 + mid, termMonths) – 1);
if (Math.abs(calculatedPayment – monthlyPayment) < 0.01) {
rate = mid;
break;
} else if (calculatedPayment < monthlyPayment) {
low = mid;
} else {
high = mid;
}
}
return rate;
}
// Simplified function to estimate term given P, I_total, r
function calculateTermFromAmortization(principal, totalInterestPaid, annualRate) {
if (principal <= 0 || totalInterestPaid < 0 || annualRate <= 0) return NaN;
var totalRepayment = principal + totalInterestPaid;
var monthlyRate = annualRate / 12;
var term = NaN;
// Using the loan payment formula rearranged to solve for n (term)
// M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
// TR = M * n
// TR = P [ i(1 + i)^n ] / [ (1 + i)^n – 1] * n
// This is hard to solve directly for n. We'll use an iterative approach.
var low = 1;
var high = 3600; // Max reasonable term in months
for (var i = 0; i < 100; i++) {
var mid = Math.round((low + high) / 2);
if (mid === 0) mid = 1; // Ensure term is at least 1 month
var monthlyPayment = principal * (monthlyRate * Math.pow(1 + monthlyRate, mid)) / (Math.pow(1 + monthlyRate, mid) – 1);
var calculatedTotalRepayment = monthlyPayment * mid;
if (Math.abs(calculatedTotalRepayment – totalRepayment) < 0.01) {
term = mid;
break;
} else if (calculatedTotalRepayment < totalRepayment) {
low = mid + 1;
} else {
high = mid – 1;
}
}
return term;
}
function updateChart(principal, totalInterestPaid) {
var ctx = getElement('repaymentChart').getContext('2d');
if (chartInstance) {
chartInstance.destroy();
}
var labels = ['Principal', 'Interest'];
var data = [principal, totalInterestPaid];
var backgroundColors = ['rgba(0, 74, 153, 0.7)', 'rgba(40, 167, 69, 0.7)'];
var borderColors = ['rgba(0, 74, 153, 1)', 'rgba(40, 167, 69, 1)'];
chartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Amount ($)',
data: data,
backgroundColor: backgroundColors,
borderColor: borderColors,
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
ticks: {
callback: function(value) {
return '$' + value.toLocaleString();
}
}
}
},
plugins: {
legend: {
display: true,
position: 'top',
},
title: {
display: true,
text: 'Principal vs. Total Interest Paid'
}
}
}
});
}
function resetResults() {
getElement("mainResult").textContent = "–";
getElement("principalResult").querySelector("span").textContent = "–";
getElement("interestRateEstimate").querySelector("span").textContent = "–";
getElement("loanTermEstimate").querySelector("span").textContent = "–";
getElement("tableTotalRepaid").textContent = "–";
getElement("tableTotalInterestPaid").textContent = "–";
getElement("tablePrincipal").textContent = "–";
getElement("tableInterestRate").textContent = "–";
getElement("tableLoanTerm").textContent = "–";
if (chartInstance) {
chartInstance.destroy();
chartInstance = null;
}
// Clear canvas if no chart
var canvas = getElement('repaymentChart');
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function resetCalculator() {
getElement("totalRepayment").value = "";
getElement("totalInterestPaid").value = "";
resetResults();
// Clear error messages
var errorElements = document.querySelectorAll('.error-message');
for (var i = 0; i < errorElements.length; i++) {
errorElements[i].textContent = "";
errorElements[i].classList.remove('visible');
}
}
function copyResults() {
var mainResult = getElement("mainResult").textContent;
var principalResult = getElement("principalResult").textContent;
var interestRateEstimate = getElement("interestRateEstimate").textContent;
var loanTermEstimate = getElement("loanTermEstimate").textContent;
var assumptions = "Key Assumptions:\n";
assumptions += "- Total Amount Repaid: " + getElement("tableTotalRepaid").textContent + "\n";
assumptions += "- Total Interest Paid: " + getElement("tableTotalInterestPaid").textContent + "\n";
assumptions += "- Estimated Interest Rate: " + getElement("tableInterestRate").textContent + "\n";
assumptions += "- Estimated Loan Term: " + getElement("tableLoanTerm").textContent + "\n";
var textToCopy = "Interest Principal Calculator Results:\n\n";
textToCopy += "Principal Amount: " + mainResult + "\n";
textToCopy += principalResult + "\n";
textToCopy += interestRateEstimate + "\n";
textToCopy += loanTermEstimate + "\n\n";
textToCopy += assumptions;
navigator.clipboard.writeText(textToCopy).then(function() {
alert('Results copied to clipboard!');
}, function(err) {
console.error('Failed to copy: ', err);
alert('Failed to copy results. Please copy manually.');
});
}
function toggleFaq(element) {
var answer = element.nextElementSibling;
if (answer.style.display === "block") {
answer.style.display = "none";
answer.classList.remove('visible');
} else {
answer.style.display = "block";
answer.classList.add('visible');
}
}
// Initial calculation on load if inputs have default values (optional)
// calculatePrincipal();
// Load Chart.js library dynamically if not present
if (typeof Chart === 'undefined') {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/chart.js@3.7.0/dist/chart.min.js';
script.onload = function() {
// Initial calculation after chart library is loaded
calculatePrincipal();
};
document.head.appendChild(script);
} else {
// Chart.js is already loaded, perform initial calculation
calculatePrincipal();
}