I am creating my own blog and would like to have a page for SIP calculation there. Created a calculator Can someone help if my formula is correct. Since this will be used by people to make financial calculation, would like some suggestions.
<script>
function KNI_Cal_SIP_MATURITY() {
//alert('called1');
var pv = parseFloat(document.getElementById("lumpsum").value);
var rate = parseFloat(document.getElementById("roi").value);
var monthlyRate = rate/12/100;
var nper = parseInt(document.getElementById("years").value);
var months = nper*12;
var pmt = parseFloat(document.getElementById("sip").value);
//alert('called2');
var pow = Math.pow(1 + rate, nper);
//alert(pow);
var fvSip = pmt * (Math.pow(1 + monthlyRate , months) - 1) / monthlyRate;
var fvPric = pv * (Math.pow((1+rate/100),nper));
var fv = (fvPric + fvSip ).toFixed(2);
var invested = (pv + pmt * months).toFixed(2);
var gain = (fv - invested).toFixed(2);
var fvStr = (fv).replace(/(\d)(?=(\d{2})+\d\.)/g, '$1,');
fvStr = fvStr.substring(0, fvStr.length - 3);
fvStr += ' (' +KNI_convertNumberToWords(fv) +'...)';
document.getElementById('total').value = fvStr;
var investedStr = (invested).replace(/(\d)(?=(\d{2})+\d\.)/g, '$1,');
investedStr = investedStr.substring(0, investedStr.length - 3);
investedStr += ' (' +KNI_convertNumberToWords(invested) +'...)';
document.getElementById('invested').value = investedStr;
var gainStr = (gain).replace(/(\d)(?=(\d{2})+\d\.)/g, '$1,');
gainStr = gainStr.substring(0, gainStr.length - 3);
gainStr += ' (' +KNI_convertNumberToWords(gain) +'...)';
document.getElementById('gain').value = gainStr;
}
</script>
Ignore function KNI_convertNumberToWords - that just converts numbers to words