Round to nearest hundredth decimal place

This commit is contained in:
Hao Tran 2025-01-09 01:23:34 -05:00
parent 8b72c9df74
commit 3dadf20dbf
2 changed files with 7 additions and 7 deletions

View File

@ -117,7 +117,7 @@
<footer>
<p>Created by <a href="https://haothitran.com">Hao Tran</a>.</p>
<p>Note: Calculations are rounded to the nearest tenth decimal. As such, there may sometimes be issues of rounding error.</p>
<p>Note: Calculations are rounded to the nearest hundredth decimal. As such, there may sometimes be issues of rounding error.</p>
</footer>
</body>
<script src="scripts/calculator.js"></script>

View File

@ -23,17 +23,17 @@ function calculator() {
// calculate pro rata
if(document.getElementById('calcProRata').checked) {
var earnedFactor = Math.round(((forceDays / termDays) + Number.EPSILON)*1000)/1000;
var unearnedFactor = Math.round(((remainingDays / termDays) + Number.EPSILON)*1000)/1000;
var earnedFactor = Math.round(((forceDays / termDays) + Number.EPSILON)*100)/100;
var unearnedFactor = Math.round(((remainingDays / termDays) + Number.EPSILON)*100)/100;
// calculate short rate
}else if(document.getElementById('calcShortRate').checked) {
var earnedFactor = Math.round(((1 - ((remainingDays / termDays ) * 0.9)) + Number.EPSILON)*1000)/1000;
var unearnedFactor = Math.round((((remainingDays / termDays) * 0.9) + Number.EPSILON)*1000)/1000;
var earnedFactor = Math.round(((1 - ((remainingDays / termDays ) * 0.9)) + Number.EPSILON)*100)/100;
var unearnedFactor = Math.round((((remainingDays / termDays) * 0.9) + Number.EPSILON)*100)/100;
}
// calculate premiums
var earnedPremium = Math.round(((totalPremium * earnedFactor) + Number.EPSILON)*1000)/1000;
var unearnedPremium = Math.round(((totalPremium * unearnedFactor) + Number.EPSILON)*1000)/1000;
var earnedPremium = Math.round(((totalPremium * earnedFactor) + Number.EPSILON)*100)/100;
var unearnedPremium = Math.round(((totalPremium * unearnedFactor) + Number.EPSILON)*100)/100;
// calculate breakdown
var calcBreak = +breakDO + +breakEO + +breakCyber + +breakLEI + +breakCGL + +breakProperty + +breakEB;