Fix simple-at-maturity payout bug and minor issues
- Fix: simple-at-maturity final payout now includes total interest (was only paying one year's interest due to dead ternary) - Fix: add type='button' to prevent form submission in WordPress - Fix: add radix 10 to parseInt - Fix: remove misleading tilde on exact average income calculation
This commit is contained in:
@ -77,7 +77,7 @@
|
|||||||
<!-- Triggers the run() function which validates, computes, and -->
|
<!-- Triggers the run() function which validates, computes, and -->
|
||||||
<!-- renders the results. -->
|
<!-- renders the results. -->
|
||||||
<!-- =============================================================== -->
|
<!-- =============================================================== -->
|
||||||
<button id="scd-btn"
|
<button type="button" id="scd-btn"
|
||||||
style="display:block;width:100%;padding:18px;background:#e66d00;color:#fff;font-size:20px;font-weight:700;border:none;border-radius:10px;cursor:pointer;margin-bottom:8px;letter-spacing:0.3px;">
|
style="display:block;width:100%;padding:18px;background:#e66d00;color:#fff;font-size:20px;font-weight:700;border:none;border-radius:10px;cursor:pointer;margin-bottom:8px;letter-spacing:0.3px;">
|
||||||
Calculate
|
Calculate
|
||||||
</button>
|
</button>
|
||||||
@ -210,7 +210,7 @@
|
|||||||
/* --- Read raw inputs --- */
|
/* --- Read raw inputs --- */
|
||||||
var a=parseFloat(document.getElementById('scd-amt').value), /* Investment amount (£) */
|
var a=parseFloat(document.getElementById('scd-amt').value), /* Investment amount (£) */
|
||||||
r=parseFloat(document.getElementById('scd-rate').value), /* Annual interest rate (%) */
|
r=parseFloat(document.getElementById('scd-rate').value), /* Annual interest rate (%) */
|
||||||
t=parseInt(document.getElementById('scd-term').value), /* Bond term (years) */
|
t=parseInt(document.getElementById('scd-term').value,10), /* Bond term (years) */
|
||||||
mEl=document.querySelector('input[name="scd-m"]:checked'), /* Selected payout method */
|
mEl=document.querySelector('input[name="scd-m"]:checked'), /* Selected payout method */
|
||||||
m=mEl?mEl.value:'cm', /* Default to compound-at-maturity */
|
m=mEl?mEl.value:'cm', /* Default to compound-at-maturity */
|
||||||
e=document.getElementById('scd-err'), /* Error container */
|
e=document.getElementById('scd-err'), /* Error container */
|
||||||
@ -245,7 +245,7 @@
|
|||||||
if(ann){
|
if(ann){
|
||||||
p=i; /* yearly payout = this year's interest */
|
p=i; /* yearly payout = this year's interest */
|
||||||
}else if(y===t){ /* final year for at-maturity modes */
|
}else if(y===t){ /* final year for at-maturity modes */
|
||||||
p=cmp?bal+i:bal+i; /* pay out current balance + final interest */
|
p=cmp?bal+i:a+totI; /* cm: full accumulated balance; sm: principal + total simple interest */
|
||||||
}
|
}
|
||||||
totP+=p;
|
totP+=p;
|
||||||
|
|
||||||
@ -281,7 +281,7 @@
|
|||||||
/* --- Populate summary cards --- */
|
/* --- Populate summary cards --- */
|
||||||
document.getElementById('scd-r-total').textContent=g(total);
|
document.getElementById('scd-r-total').textContent=g(total);
|
||||||
document.getElementById('scd-r-interest').textContent=g(netI);
|
document.getElementById('scd-r-interest').textContent=g(netI);
|
||||||
document.getElementById('scd-r-annual').textContent=(ann?'':'~')+g(yrInc)+(ann?'/yr':'/yr avg');
|
document.getElementById('scd-r-annual').textContent=g(yrInc)+(ann?'/yr':'/yr avg');
|
||||||
document.getElementById('scd-r-eff').textContent=eff.toFixed(2)+'%';
|
document.getElementById('scd-r-eff').textContent=eff.toFixed(2)+'%';
|
||||||
|
|
||||||
/* --- Update security tier display --- */
|
/* --- Update security tier display --- */
|
||||||
|
|||||||
Reference in New Issue
Block a user